* Most graphs following the same specification/estimation are run in loop, to search a specific figure/table from the paper search for e.g. "figure 1 panel a", "table 1 panel b", "figure s1", "table s1"
timer on 1
* PREAMBLE
clear all
set more off
set graphics off
capture log close
set maxvar 22000

* DIRECTORIES
cd ..

* PACKAGES
*ssc install coefplot
*ssc install reghdfe /* update if old version */
*ssc install ivreghdfe
*ssc install binscatterhist
*ssc install binscatter
*ssc install addplot
*ssc install lgraph
*ssc install ivreg2
*ssc install ranktest
*ssc install sutex
*ssc install ftools


* DATA LOAD
use data/data_county_2020.dta

* VARIOUS GLOBALS FOR GRAPHS FORMATTING AND REGRESSIONS
if "run"=="run"{

* first stage
global general_options_fs_fxnc " graphregion(fcolor(white))  legend(off) ytitle("Fox News Viewership") xtitle("Fox News Channel Position (Standardized)")  color(teal) lcolor(maroon) "
global general_options_fs_cnn " graphregion(fcolor(white))  legend(off) ytitle("CNN Viewership") xtitle("CNN Position (Standardized)")  color(teal) lcolor(maroon) "
global general_options_fs_msnbc " graphregion(fcolor(white))  legend(off) ytitle("MSNBC Viewership") xtitle("MSNBC Position (Standardized)")  color(teal) lcolor(maroon) "

* reduced form
global general_options_reduced "graphregion(margin(3 6 3 3)) graphregion(fcolor(white)) vertical legend(off) ytitle("Effect on Mobility (RF)") yline(0, lpattern(dash) lcolor(gray)) xsize(8) xtitle("Date") ciopts(color(teal)) msize(small) symbol(circle_hollow) color(maroon)"
global general_options_reduced_p "graphregion(margin(3 6 3 3)) graphregion(fcolor(white)) vertical legend(off) ytitle("Effect on Purchases (RF)") yline(0, lpattern(dash) lcolor(gray)) xsize(8) xtitle("Date") ciopts(color(teal)) msize(small) symbol(circle_hollow) color(maroon)"
global general_options_reduced_ratioc "graphregion(margin(3 6 3 3))  graphregion(fcolor(white)) vertical legend(off) ytitle("Effect on Infection Rate (RF)") yline(0, lpattern(dash) lcolor(gray)) xsize(8) xtitle("Date") ciopts(color(teal)) msize(small) symbol(circle_hollow) color(maroon)"
global general_options_reduced_ratiod"graphregion(margin(3 6 3 3))  graphregion(fcolor(white)) vertical legend(off) ytitle("Effect on Deaths Per Capita (RF)") yline(0, lpattern(dash) lcolor(gray)) xsize(8) xtitle("Date") ciopts(color(teal)) msize(small) symbol(circle_hollow) color(maroon)"
global general_options_reduced_incrc"graphregion(margin(3 6 3 3)) graphregion(fcolor(white)) vertical legend(off) ytitle("Effect on Infections (RF)") yline(0, lpattern(dash) lcolor(gray)) xsize(8) xtitle("Date") ciopts(color(teal)) msize(small) symbol(circle_hollow) color(maroon)"
global general_options_reduced_incrd"graphregion(margin(3 6 3 3)) graphregion(fcolor(white)) vertical legend(off) ytitle("Effect on Deaths (RF)") yline(0, lpattern(dash) lcolor(gray)) xsize(8) xtitle("Date") ciopts(color(teal)) msize(small) symbol(circle_hollow) color(maroon)"
global other_options_reduced " graphregion(fcolor(white)) vertical legend(off) ytitle("Effect on `y' (RF)") yline(0, lpattern(dash) lcolor(gray)) xsize(8) ciopts(color(teal)) msize(small) symbol(circle_hollow) color(maroon)"

* ols
global general_options_ols "graphregion(margin(3 6 3 3))  graphregion(fcolor(white)) vertical legend(off) ytitle("Effect on Mobility (OLS)") yline(0, lpattern(dash) lcolor(gray)) xsize(8) xtitle("Date") ciopts(color(teal)) msize(small) symbol(circle_hollow) color(maroon)"
global general_options_ols_p "graphregion(margin(3 6 3 3))  graphregion(fcolor(white)) vertical legend(off) ytitle("Effect on Purchases (OLS)") yline(0, lpattern(dash) lcolor(gray)) xsize(8) xtitle("Date") ciopts(color(teal)) msize(small) symbol(circle_hollow) color(maroon)"
global general_options_ols_ratioc "graphregion(margin(3 6 3 3))  graphregion(fcolor(white)) vertical legend(off) ytitle("Effect on Infection Rate (OLS)") yline(0, lpattern(dash) lcolor(gray)) xsize(8) xtitle("Date") ciopts(color(teal)) msize(small) symbol(circle_hollow) color(maroon)"
global general_options_ols_ratiod "graphregion(margin(3 6 3 3))  graphregion(fcolor(white)) vertical legend(off) ytitle("Effect on Deaths Per Capita (OLS)") yline(0, lpattern(dash) lcolor(gray)) xsize(8) xtitle("Date") ciopts(color(teal)) msize(small) symbol(circle_hollow) color(maroon)"
global general_options_ols_incrc "graphregion(margin(3 6 3 3))  graphregion(fcolor(white)) vertical legend(off) ytitle("Effect on Infections (OLS)") yline(0, lpattern(dash) lcolor(gray)) xsize(8) xtitle("Date") ciopts(color(teal)) msize(small) symbol(circle_hollow) color(maroon)"
global general_options_ols_incrd "graphregion(margin(3 6 3 3))  graphregion(fcolor(white)) vertical legend(off) ytitle("Effect on Deaths (OLS)") yline(0, lpattern(dash) lcolor(gray)) xsize(8) xtitle("Date") ciopts(color(teal)) msize(small) symbol(circle_hollow) color(maroon)"
global other_options_ols "graphregion(margin(3 6 3 3))  graphregion(fcolor(white)) vertical legend(off) ytitle("Effect on `y' (OLS)") yline(0, lpattern(dash) lcolor(gray)) xsize(8) ciopts(color(teal)) msize(small) symbol(circle_hollow) color(maroon)"

* 2sls
global general_options "graphregion(margin(3 6 3 3))  graphregion(fcolor(white)) vertical legend(off) ytitle("Effect on Mobility (2SLS)") yline(0, lpattern(dash) lcolor(gray)) xsize(8) xtitle("Date") ciopts(color(teal)) msize(small) symbol(circle_hollow) color(maroon)"
global general_options_p "graphregion(margin(3 6 3 3))  graphregion(fcolor(white)) vertical legend(off) ytitle("Effect on Purchases (2SLS)") yline(0, lpattern(dash) lcolor(gray)) xsize(8) xtitle("Date") ciopts(color(teal)) msize(small) symbol(circle_hollow) color(maroon)"
global general_options_ratioc "graphregion(margin(3 6 3 3))  graphregion(fcolor(white)) vertical legend(off) ytitle("Effect on Infection Rate (2SLS)") yline(0, lpattern(dash) lcolor(gray)) xsize(8) xtitle("Date") ciopts(color(teal)) msize(small) symbol(circle_hollow) color(maroon)"
global general_options_ratiod "graphregion(margin(3 6 3 3))  graphregion(fcolor(white)) vertical legend(off) ytitle("Effect on Deaths Per Capita (2SLS)") yline(0, lpattern(dash) lcolor(gray)) xsize(8) xtitle("Date") ciopts(color(teal)) msize(small) symbol(circle_hollow) color(maroon)"
global general_options_incrc "graphregion(margin(3 6 3 3))  graphregion(fcolor(white)) vertical legend(off) ytitle("Effect on Infections (2SLS)") yline(0, lpattern(dash) lcolor(gray)) xsize(8) xtitle("Date") ciopts(color(teal)) msize(small) symbol(circle_hollow) color(maroon)"
global general_options_incrd "graphregion(margin(3 6 3 3))  graphregion(fcolor(white)) vertical legend(off) ytitle("Effect on Deaths (2SLS)") yline(0, lpattern(dash) lcolor(gray)) xsize(8) xtitle("Date") ciopts(color(teal)) msize(small) symbol(circle_hollow) color(maroon)"
global other_options_iv 	  "graphregion(margin(3 6 3 3))  graphregion(fcolor(white)) vertical legend(off) ytitle("Effect on `y' (2SLS)") yline(0, lpattern(dash) lcolor(gray)) xsize(8) xtitle("Date")  ciopts(color(teal)) msize(small) symbol(circle_hollow) color(maroon)"
global x_line "xline(0.518  1.482, lpattern(dot) lcolor(gray)) xlabel(0.518 "March 17th"  1.482 "May 10th")"

* other graphs
global general_options2 "graphregion(margin(3 6 3 3))  graphregion(fcolor(white)) vertical legend(off) ytitle("Effect on Mobility (RF)") yline(0, lpattern(dash) lcolor(gray)) xsize(8) xtitle("Date") ciopts(color(teal)) msize(medsmall) symbol(plus) color(maroon)"	


* dates period
global dates_coefplot_mobility_sf "_21946 _21947 _21948 _21949 _21950 _21951 _21952 _21953 _21954 _21955 _21956 _21957 _21958 _21959 _21960 _21961 _21962 _21963 _21964 _21965 _21966 _21967 _21968 _21969 _21970 _21971 _21972 _21973 _21974 _21975 _21976 _21977 _21978 _21979 _21980 _21981 _21982 _21983 _21984 _21985 _21986 _21987 _21988 _21989 _21990 _21991 _21992 _21993 _21994 _21995 _21996 _21997 _21998 _21999 _22000 _22001 _22002 _22003 _22004 _22005 _22006 _22007 _22008 _22009 _22010 _22011 _22012 _22013 _22014 _22015 _22016 _22017 _22018 _22019 _22020 _22021 _22022 _22023 _22024 _22025 _22026 _22027 _22028 _22029 _22030 _22031 _22032 _22033 _22034 _22035"
global x_line_sf "xline(0.511 0.665 0.830 0.983 1.170 1.324 1.489, lpattern(dot) lwidth(1) lcolor(gray)) xlabel(0.511 "February 1st" 0.665 "February 15th" 0.830 "March 1st" 0.983 "March 15th" 1.170 "April 1st" 1.324 "April 15th" 1.489 "April 30th")"
global x_line_multi "xline(1 15 30 44 60 74 89, lpattern(dot) lwidth(1) lcolor(gray)) xlabel(1 "February 1st" 15 "February 15th" 30 "March 1st" 44 "March 15th" 60 "April 1st" 74 "April 15th" 89 "April 30th")"

* globals for other networks controls
global other_rtgs_fxnc "msnbc_rtg cnn_rtg"
global other_rtgs_cnn "msnbc_rtg fxnc_rtg"
global other_rtgs_msnbc "fxnc_rtg cnn_rtg"

global other_ch_fxnc "msnbc cnn"
global other_ch_cnn "msnbc fxnc"
global other_ch_msnbc "fxnc cnn"

* iteration vars
global outcomes_pick "sd_sf_dist_fr_home sd_sf_median_nohome_time"
global outcomes_pick1 "ratio_cases_pop ratio_deaths_pop st_incr_cases_7_ st_incr_deaths_7_"
global outcomes_pick2 "sd_sf_dist_fr_home sd_sf_median_nohome_time sd_sf_pt_work_dev sd_sf_ft_work_dev sd_sf_home_dev_count"
global outcomes_pick4 "tot_expgroc"

* controls
global full_controls1 "pop_dens_county landarea_county age_imb pct_food_stamps_county med_rep16 med_rep12 pct_nohs_county pct_college_county med_white med_black pct_male_county"


}
*

* SAFEGRAPH MOBILITY (with baseline, reduced form, ols and 2sls)  
* figure 1 panel a, figure 1 panel b, figure s6, figure s7, figure s13, table s4, table s5
global safegraph=1
if ${safegraph}==1 {
foreach cl in state_fips {
	foreach network in fxnc {
	* RF
			foreach y of global outcomes_pick2  {
				cap drop _est*
				eststo clear
					forvalues date=21946/22035 {
					if dow`date'[1]==0{
					global baseline "`y'_sun"
					}					
					if dow`date'[1]==1{
					global baseline "`y'_mon"
					}					
					if dow`date'[1]==2{
					global baseline "`y'_tue"
					}					
					if dow`date'[1]==3{
					global baseline "`y'_wed"
					}					
					if dow`date'[1]==4{
					global baseline "`y'_thu"
					}					
					if dow`date'[1]==5{
					global baseline "`y'_fri"
					}					
					if dow`date'[1]==6{
					global baseline "`y'_sat"
					}
					reghdfe `y'`date' `network' [aweight=pop], absorb(state_fips one##c.($baseline $full_controls1 ${other_rtgs_`network'})) cluster(`cl')
					cap eststo _`date'
					}
				coefplot $dates_coefplot_mobility_sf, $general_options_reduced $x_line_sf keep(`network') 
				graph export "output/rf_2016_`network'_censuscontrols1_`cl'_`y'.pdf", replace
				}	

	*
	* OLS
			foreach y of global outcomes_pick2 {
				eststo clear
					forvalues date=21946/22035 {
					if dow`date'[1]==0{
					global baseline "`y'_sun"
					}					
					if dow`date'[1]==1{
					global baseline "`y'_mon"
					}					
					if dow`date'[1]==2{
					global baseline "`y'_tue"
					}					
					if dow`date'[1]==3{
					global baseline "`y'_wed"
					}					
					if dow`date'[1]==4{
					global baseline "`y'_thu"
					}					
					if dow`date'[1]==5{
					global baseline "`y'_fri"
					}					
					if dow`date'[1]==6{
					global baseline "`y'_sat"
					}

					cap qui reghdfe `y'`date' `network'_rtg [aweight=pop], absorb(state_fips one##c.($baseline $full_controls1 ${other_rtgs_`network'})) cluster(`cl')
					cap eststo _`date'
					}
				coefplot $dates_coefplot_mobility_sf, $general_options_ols $x_line_sf keep(`network'_rtg) 
				graph export "output/ols_2016_`network'_censuscontrols1_`cl'_`y'.pdf", replace
				}
	*
	* 2SLS
			foreach y of global outcomes_pick2 {
				cap drop _est*
				eststo clear
					forvalues date=21946/22035 {
					if dow`date'[1]==0{
					global baseline "`y'_sun"
					}					
					if dow`date'[1]==1{
					global baseline "`y'_mon"
					}					
					if dow`date'[1]==2{
					global baseline "`y'_tue"
					}					
					if dow`date'[1]==3{
					global baseline "`y'_wed"
					}					
					if dow`date'[1]==4{
					global baseline "`y'_thu"
					}					
					if dow`date'[1]==5{
					global baseline "`y'_fri"
					}					
					if dow`date'[1]==6{
					global baseline "`y'_sat"
					}
					cap qui ivreghdfe `y'`date' (`network'_rtg= `network') [aweight=pop], absorb(state_fips one##c.($baseline $full_controls1 ${other_rtgs_`network'})) cluster(`cl')
					cap eststo _`date'
					}
				macro drop options					
				coefplot $dates_coefplot_mobility_sf, $general_options $x_line_sf keep(`network'_rtg) 
				graph export "output/2sls_2016_`network'_censuscontrols1_`cl'_`y'.pdf", replace
				}
	*
	}
}
*				
}
*

* FIRST STAGE AND SUMMARY STATISTICS (county level)
* figure s1, table S2
global first_stage=1
if ${first_stage}==1 {
preserve
foreach network in fxnc {
di fxnc[1]
replace `network'=abs(`network')
ivreghdfe sf_dist_fr_home22038 (rtgxxfxnc_2020=`network') [aweight=pop], absorb(state_fips one##c.($full_controls1 ${other_rtgs_`network'})) cluster(state_fips) first
gen sample_sutex=1 if e(sample)==1
sutex rtgxxfxnc_2020 rtgxxcnn_2020 rtgxxmsnbc_2020 orig_pos_fxnc_w orig_pos_cnn_w orig_pos_msnbc_w pop pop_dens_county landarea_county age_imb pct_food_stamps_county med_rep16 med_rep12 pct_nohs_county pct_college_county med_white med_black pct_male_county if sample_sutex==1, minmax
binscatter rtgxxfxnc_2020 `network' [aweight=pop], absorb(state_fips) controls($full_controls1 ${other_rtgs_`network'}) nquantiles(25) ${general_options_fs_`network'}
graph export "output/firststage_`network'_censuscontrols1_state_fips.pdf", replace
restore
}
}
*

* BALANCE CHECKS ON INSTRUMENT (county level)
* table s1
global instrument_bcheck=1
if ${instrument_bcheck}==1 {
preserve
foreach var in pop_dens_county age_imb pct_food_stamps_county med_rep16 med_rep12 landarea_county pct_nohs_county  pct_college_county med_white med_black pct_male_county {
egen sd_`var'=sd(`var')
replace `var'=`var'/sd_`var'
}

di fxnc[1]
replace fxnc=abs(fxnc)
di fxnc[1]

foreach var in fxnc {
* Checks on Instrument
reghdfe age_imb `var' pop_dens_county   pct_food_stamps_county med_rep16 med_rep12 landarea_county pct_nohs_county  	pct_college_county med_white med_black pct_male_county [aweight=pop] , absorb(state_fips one##c.(cnn_rtg msnbc_rtg )) cluster(state_fips) nocons 
reghdfe pct_food_stamps_county `var'  pop_dens_county age_imb  med_rep16 med_rep12 pct_nohs_county  landarea_county	pct_college_county med_white med_black pct_male_county [aweight=pop] , absorb(state_fips one##c.(cnn_rtg msnbc_rtg )) cluster(state_fips) nocons 
reghdfe pct_college_county `var'  pop_dens_county age_imb pct_food_stamps_county med_rep16 med_rep12 landarea_county pct_nohs_county  med_white med_black pct_male_county [aweight=pop] , absorb(state_fips one##c.(cnn_rtg msnbc_rtg )) cluster(state_fips) nocons 
reghdfe pct_male_county `var'  pop_dens_county age_imb pct_food_stamps_county med_rep16 med_rep12	landarea_county pct_nohs_county pct_college_county med_white med_black  [aweight=pop] , absorb(state_fips one##c.(cnn_rtg msnbc_rtg )) cluster(state_fips) nocons 
reghdfe pct_nohs_county `var'  pop_dens_county age_imb pct_food_stamps_county med_rep16 med_rep12	landarea_county  pct_college_county med_white med_black pct_male_county [aweight=pop] , absorb(state_fips one##c.(cnn_rtg msnbc_rtg )) cluster(state_fips) nocons 
reghdfe med_black `var'  pop_dens_county age_imb pct_food_stamps_county med_rep16 med_rep12	landarea_county pct_nohs_county pct_college_county med_white pct_male_county [aweight=pop] , absorb(state_fips one##c.(cnn_rtg msnbc_rtg )) cluster(state_fips) nocons 
reghdfe med_white `var'  pop_dens_county age_imb pct_food_stamps_county med_rep16 med_rep12	landarea_county pct_nohs_county pct_college_county med_black pct_male_county [aweight=pop] , absorb(state_fips one##c.(cnn_rtg msnbc_rtg )) cluster(state_fips) nocons 
reghdfe pop_dens_county `var'   age_imb pct_food_stamps_county med_rep16 med_rep12 landarea_county 	 pct_nohs_county  pct_college_county med_white med_black pct_male_county [aweight=pop] , absorb(state_fips one##c.(cnn_rtg msnbc_rtg )) cluster(state_fips) nocons 
reghdfe landarea_county  `var'   pop_dens_county age_imb pct_food_stamps_county med_rep16	med_rep12 pct_nohs_county pct_college_county med_white med_black pct_male_county [aweight=pop] , absorb(state_fips one##c.(cnn_rtg msnbc_rtg )) cluster(state_fips) nocons
}
restore
}
*

* TIME SERIES OF VARIABLES (county level)
* figure s3, figure s4, figure s5
global covid_tseries=1
if ${covid_tseries}==1 {
preserve
qui ivreghdfe sf_dist_fr_home22038 (rtgxxfxnc_2020=fxnc) [aweight=pop], absorb(state_fips one##c.($full_controls1 ${other_rtgs_fxnc})) cluster(state_fips) first
keep if e(sample)==1
qui keep ratio_cases_pop* ratio_deaths_pop* incr_cases_7_* incr_deaths_7_* cases* deaths* sf_dist_fr_home* sf_median_nohome_time* tot_expgroc* fips_county
qui  reshape long incr_cases_7_ incr_deaths_7_ sf_dist_fr_home sf_median_nohome_time cases deaths tot_expgroc, i(fips_county) j(date)
keep if inrange(date,21946,22035)
foreach var in incr_cases_7_ incr_deaths_7_ sf_dist_fr_home sf_median_nohome_time cases deaths tot_expgroc {
lgraph `var' date , xtitle("Date") ytitle("`var'") graphregion(margin(3 6 3 3)) xsize(8) xlabel(21946 "February 1st" 22035 "April 30th")
graph export "output/timeseries_`var'.pdf", replace
}
restore
}
*	

* POLYNOMIALS AND INTERACTIONS (balance check controls)	
* figure s9 panel a, figure s9 panel b
global rc_polynomials_interactions=1
if ${rc_polynomials_interactions}==1 {

foreach check_var in pop_dens_county landarea_county pct_food_stamps_county pct_nohs_county med_white {
cap gen `check_var'_2=`check_var'^2	
cap gen `check_var'_3=`check_var'^3	
cap gen `check_var'_fxnc=`check_var'*fxnc
}

global full_controls_var1 "pop_dens_county_2 pop_dens_county_3"
global full_controls_var2 "landarea_county_2 landarea_county_3"
global full_controls_var3 "pct_food_stamps_county_2 pct_food_stamps_county_3"
global full_controls_var4 "pct_nohs_county_2 pct_nohs_county_3"
global full_controls_var5 "med_white_2 med_white_3"
global full_controls_var6 "pop_dens_county_fxnc"
global full_controls_var7 "landarea_county_fxnc"
global full_controls_var8 "pct_food_stamps_county_fxnc"
global full_controls_var9 "pct_nohs_county_fxnc"
global full_controls_var10 "med_white_fxnc"

* RF *
foreach cl in state_fips {
	* Main outcomes RF

			foreach y of global outcomes_pick {
				foreach controls_set in full_controls_var1 full_controls_var2 full_controls_var3 full_controls_var4 full_controls_var5 full_controls_var6 full_controls_var7 full_controls_var8 full_controls_var9 full_controls_var10 {				
					forvalues date=21946/22035 {
					if dow`date'[1]==0{
					global baseline "`y'_sun"
					}					
					if dow`date'[1]==1{
					global baseline "`y'_mon"
					}					
					if dow`date'[1]==2{
					global baseline "`y'_tue"
					}					
					if dow`date'[1]==3{
					global baseline "`y'_wed"
					}					
					if dow`date'[1]==4{
					global baseline "`y'_thu"
					}					
					if dow`date'[1]==5{
					global baseline "`y'_fri"
					}					
					if dow`date'[1]==6{
					global baseline "`y'_sat"
					}
					cap qui reghdfe `y'`date' fxnc [aweight=pop], absorb(state_fips one##c.($baseline $full_controls1 ${`controls_set'} msnbc_rtg cnn_rtg)) cluster(`cl')
					qui lincom _b[fxnc]
					global coef_`controls_set'_`date'=r(estimate)
					global lb_`controls_set'_`date'=r(lb)
					global ub_`controls_set'_`date'=r(ub)
					macro drop baseline
					}
				matrix define matrix_coef_`controls_set'=(${coef_`controls_set'_21946} \ ${coef_`controls_set'_21947} \ ${coef_`controls_set'_21948} \ ${coef_`controls_set'_21949} \ ${coef_`controls_set'_21950} \ ${coef_`controls_set'_21951} \ ${coef_`controls_set'_21952} \ ${coef_`controls_set'_21953} \ ${coef_`controls_set'_21954} \ ${coef_`controls_set'_21955} \ ${coef_`controls_set'_21956} \ ${coef_`controls_set'_21957} \ ${coef_`controls_set'_21958} \ ${coef_`controls_set'_21959} \ ${coef_`controls_set'_21960} \ ${coef_`controls_set'_21961} \ ${coef_`controls_set'_21962} \ ${coef_`controls_set'_21963} \ ${coef_`controls_set'_21964} \ ${coef_`controls_set'_21965} \ ${coef_`controls_set'_21966} \ ${coef_`controls_set'_21967} \ ${coef_`controls_set'_21968} \ ${coef_`controls_set'_21969} \ ${coef_`controls_set'_21970} \ ${coef_`controls_set'_21971} \ ${coef_`controls_set'_21972} \ ${coef_`controls_set'_21973} \ ${coef_`controls_set'_21974} \ ${coef_`controls_set'_21975} \ ${coef_`controls_set'_21976} \ ${coef_`controls_set'_21977} \ ${coef_`controls_set'_21978} \ ${coef_`controls_set'_21979} \ ${coef_`controls_set'_21980} \ ${coef_`controls_set'_21981} \ ${coef_`controls_set'_21982} \ ${coef_`controls_set'_21983} \ ${coef_`controls_set'_21984} \ ${coef_`controls_set'_21985} \ ${coef_`controls_set'_21986} \ ${coef_`controls_set'_21987} \ ${coef_`controls_set'_21988} \ ${coef_`controls_set'_21989} \ ${coef_`controls_set'_21990} \ ${coef_`controls_set'_21991} \ ${coef_`controls_set'_21992} \ ${coef_`controls_set'_21993} \ ${coef_`controls_set'_21994} \ ${coef_`controls_set'_21995} \ ${coef_`controls_set'_21996} \ ${coef_`controls_set'_21997} \ ${coef_`controls_set'_21998} \ ${coef_`controls_set'_21999} \ ${coef_`controls_set'_22000} \ ${coef_`controls_set'_22001} \ ${coef_`controls_set'_22002} \ ${coef_`controls_set'_22003} \ ${coef_`controls_set'_22004} \ ${coef_`controls_set'_22005} \ ${coef_`controls_set'_22006} \ ${coef_`controls_set'_22007} \ ${coef_`controls_set'_22008} \ ${coef_`controls_set'_22009} \ ${coef_`controls_set'_22010} \ ${coef_`controls_set'_22011} \ ${coef_`controls_set'_22012} \ ${coef_`controls_set'_22013} \ ${coef_`controls_set'_22014} \ ${coef_`controls_set'_22015} \ ${coef_`controls_set'_22016} \ ${coef_`controls_set'_22017} \ ${coef_`controls_set'_22018} \ ${coef_`controls_set'_22019} \ ${coef_`controls_set'_22020} \ ${coef_`controls_set'_22021} \ ${coef_`controls_set'_22022} \ ${coef_`controls_set'_22023} \ ${coef_`controls_set'_22024} \ ${coef_`controls_set'_22025} \ ${coef_`controls_set'_22026} \ ${coef_`controls_set'_22027} \ ${coef_`controls_set'_22028} \ ${coef_`controls_set'_22029} \ ${coef_`controls_set'_22030} \ ${coef_`controls_set'_22031} \ ${coef_`controls_set'_22032} \ ${coef_`controls_set'_22033} \ ${coef_`controls_set'_22034} \ ${coef_`controls_set'_22035})
				matrix rownames matrix_coef_`controls_set'= _21946 _21947 _21948 _21949 _21950 _21951 _21952 _21953 _21954 _21955 _21956 _21957 _21958 _21959 _21960 _21961 _21962 _21963 _21964 _21965 _21966 _21967 _21968 _21969 _21970_21971 _21972 _21973 _21974 _21975 _21976 _21977 _21978 _21979 _21980 _21981 _21982 _21983 _21984 _21985 _21986 _21987 _21988 _21989 _21990 _21991 _21992 _21993 _21994 _21995 _21996 _21997 _21998 _21999 _22000 _22001 _22002 _22003 _22004 _22005 _22006 _22007 _22008 _22009 _22010 _22011 _22012 _22013 _22014 _22015 _22016 _22017 _22018 _22019 _22020 _22021 _22022 _22023 _22024 _22025 _22026 _22027 _22028 _22029 _22030 _22031 _22032 _22033 _22034 _22035
				matrix colnames matrix_coef_`controls_set'=b	
				matrix matrix_coef_`controls_set'=matrix_coef_`controls_set''
				
				matrix define matrix_ci_`controls_set'=(${lb_`controls_set'_21946} , ${lb_`controls_set'_21947} , ${lb_`controls_set'_21948} , ${lb_`controls_set'_21949} , ${lb_`controls_set'_21950} , ${lb_`controls_set'_21951} , ${lb_`controls_set'_21952} , ${lb_`controls_set'_21953} , ${lb_`controls_set'_21954} , ${lb_`controls_set'_21955} , ${lb_`controls_set'_21956} , ${lb_`controls_set'_21957} , ${lb_`controls_set'_21958} , ${lb_`controls_set'_21959} , ${lb_`controls_set'_21960} , ${lb_`controls_set'_21961} , ${lb_`controls_set'_21962} , ${lb_`controls_set'_21963} , ${lb_`controls_set'_21964} , ${lb_`controls_set'_21965} , ${lb_`controls_set'_21966} , ${lb_`controls_set'_21967} , ${lb_`controls_set'_21968} , ${lb_`controls_set'_21969} , ${lb_`controls_set'_21970} , ${lb_`controls_set'_21971} , ${lb_`controls_set'_21972} , ${lb_`controls_set'_21973} ,${lb_`controls_set'_21974} , ${lb_`controls_set'_21975} , ${lb_`controls_set'_21976} , ${lb_`controls_set'_21977} , ${lb_`controls_set'_21978} , ${lb_`controls_set'_21979} , ${lb_`controls_set'_21980} , ${lb_`controls_set'_21981} , ${lb_`controls_set'_21982} , ${lb_`controls_set'_21983} , ${lb_`controls_set'_21984} , ${lb_`controls_set'_21985} , ${lb_`controls_set'_21986} , ${lb_`controls_set'_21987} , ${lb_`controls_set'_21988} , ${lb_`controls_set'_21989} , ${lb_`controls_set'_21990} , ${lb_`controls_set'_21991} , ${lb_`controls_set'_21992} , ${lb_`controls_set'_21993} , ${lb_`controls_set'_21994} , ${lb_`controls_set'_21995} , ${lb_`controls_set'_21996} , ${lb_`controls_set'_21997} , ${lb_`controls_set'_21998} , ${lb_`controls_set'_21999} , ${lb_`controls_set'_22000} , ${lb_`controls_set'_22001} , ${lb_`controls_set'_22002} , ${lb_`controls_set'_22003} , ${lb_`controls_set'_22004} , ${lb_`controls_set'_22005} , ${lb_`controls_set'_22006} , ${lb_`controls_set'_22007} , ${lb_`controls_set'_22008} , ${lb_`controls_set'_22009} , ${lb_`controls_set'_22010} , ${lb_`controls_set'_22011} , ${lb_`controls_set'_22012} , ${lb_`controls_set'_22013} , ${lb_`controls_set'_22014} , ${lb_`controls_set'_22015} , ${lb_`controls_set'_22016} , ${lb_`controls_set'_22017} , ${lb_`controls_set'_22018} , ${lb_`controls_set'_22019} , ${lb_`controls_set'_22020} , ${lb_`controls_set'_22021} , ${lb_`controls_set'_22022} , ${lb_`controls_set'_22023} , ${lb_`controls_set'_22024} , ${lb_`controls_set'_22025} , ${lb_`controls_set'_22026} , ${lb_`controls_set'_22027} , ${lb_`controls_set'_22028} , ${lb_`controls_set'_22029} , ${lb_`controls_set'_22030} , ${lb_`controls_set'_22031} , ${lb_`controls_set'_22032} , ${lb_`controls_set'_22033} , ${lb_`controls_set'_22034} , ${lb_`controls_set'_22035} \ ${ub_`controls_set'_21946} , ${ub_`controls_set'_21947} , ${ub_`controls_set'_21948} , ${ub_`controls_set'_21949} , ${ub_`controls_set'_21950} , ${ub_`controls_set'_21951} , ${ub_`controls_set'_21952} , ${ub_`controls_set'_21953} , ${ub_`controls_set'_21954} , ${ub_`controls_set'_21955} , ${ub_`controls_set'_21956} , ${ub_`controls_set'_21957} , ${ub_`controls_set'_21958} , ${ub_`controls_set'_21959} , ${ub_`controls_set'_21960} , ${ub_`controls_set'_21961} , ${ub_`controls_set'_21962} , ${ub_`controls_set'_21963} , ${ub_`controls_set'_21964} , ${ub_`controls_set'_21965} , ${ub_`controls_set'_21966} , ${ub_`controls_set'_21967} , ${ub_`controls_set'_21968} , ${ub_`controls_set'_21969} , ${ub_`controls_set'_21970} , ${ub_`controls_set'_21971} , ${ub_`controls_set'_21972} , ${ub_`controls_set'_21973} ,${ub_`controls_set'_21974} , ${ub_`controls_set'_21975} , ${ub_`controls_set'_21976} , ${ub_`controls_set'_21977} , ${ub_`controls_set'_21978} , ${ub_`controls_set'_21979} ,${ub_`controls_set'_21980} , ${ub_`controls_set'_21981} , ${ub_`controls_set'_21982} , ${ub_`controls_set'_21983} , ${ub_`controls_set'_21984} , ${ub_`controls_set'_21985} , ${ub_`controls_set'_21986} , ${ub_`controls_set'_21987} , ${ub_`controls_set'_21988} , ${ub_`controls_set'_21989} , ${ub_`controls_set'_21990} , ${ub_`controls_set'_21991} , ${ub_`controls_set'_21992} , ${ub_`controls_set'_21993} , ${ub_`controls_set'_21994} , ${ub_`controls_set'_21995} , ${ub_`controls_set'_21996} , ${ub_`controls_set'_21997} , ${ub_`controls_set'_21998} , ${ub_`controls_set'_21999} , ${ub_`controls_set'_22000} , ${ub_`controls_set'_22001} , ${ub_`controls_set'_22002} , ${ub_`controls_set'_22003} , ${ub_`controls_set'_22004} , ${ub_`controls_set'_22005} , ${ub_`controls_set'_22006} , ${ub_`controls_set'_22007} , ${ub_`controls_set'_22008} , ${ub_`controls_set'_22009} , ${ub_`controls_set'_22010} , ${ub_`controls_set'_22011} , ${ub_`controls_set'_22012} , ${ub_`controls_set'_22013} , ${ub_`controls_set'_22014} , ${ub_`controls_set'_22015} , ${ub_`controls_set'_22016} , ${ub_`controls_set'_22017} , ${ub_`controls_set'_22018} , ${ub_`controls_set'_22019} , ${ub_`controls_set'_22020} , ${ub_`controls_set'_22021} , ${ub_`controls_set'_22022} , ${ub_`controls_set'_22023} , ${ub_`controls_set'_22024} , ${ub_`controls_set'_22025} , ${ub_`controls_set'_22026} , ${ub_`controls_set'_22027} , ${ub_`controls_set'_22028} , ${ub_`controls_set'_22029} , ${ub_`controls_set'_22030} , ${ub_`controls_set'_22031} , ${ub_`controls_set'_22032} , ${ub_`controls_set'_22033} , ${ub_`controls_set'_22034} , ${ub_`controls_set'_22035})
				}
			coefplot ///
			(matrix(matrix_coef_full_controls_var1),  ci(matrix_ci_full_controls_var1)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var2),  ci(matrix_ci_full_controls_var2)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var3),  ci(matrix_ci_full_controls_var3)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var4),  ci(matrix_ci_full_controls_var4)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var5),  ci(matrix_ci_full_controls_var5)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var6),  ci(matrix_ci_full_controls_var6)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var7),  ci(matrix_ci_full_controls_var7)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var8),  ci(matrix_ci_full_controls_var8)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var9),  ci(matrix_ci_full_controls_var9)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var10), ci(matrix_ci_full_controls_var10) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var1),  ci(matrix_ci_full_controls_var1)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var2),  ci(matrix_ci_full_controls_var2)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var3),  ci(matrix_ci_full_controls_var3)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var4),  ci(matrix_ci_full_controls_var4)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var5),  ci(matrix_ci_full_controls_var5)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var6),  ci(matrix_ci_full_controls_var6)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var7),  ci(matrix_ci_full_controls_var7)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var8),  ci(matrix_ci_full_controls_var8)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var9),  ci(matrix_ci_full_controls_var9)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var10), ci(matrix_ci_full_controls_var10) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var1),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_full_controls_var2),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_full_controls_var3),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_full_controls_var4),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_full_controls_var5),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_full_controls_var6),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_full_controls_var7),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_full_controls_var8),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_full_controls_var9),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_full_controls_var10), noci color(maroon) mlwidth(thin)) ///
			, $general_options2 $x_line_multi nooffsets
			graph export "output/rf_`y'_polynomials_interactions.pdf", replace
			}
		*
		}
*
}
*

* DROPPING INDIVIDUAL CONTROLS 
* figure s10
global drop_one_control=1
if ${drop_one_control}==1 {
global full_controls_var1 " 				landarea_county age_imb pct_food_stamps_county med_rep16 med_rep12 pct_nohs_county pct_college_county med_white med_black pct_male_county"
global full_controls_var2 " pop_dens_county 				age_imb pct_food_stamps_county med_rep16 med_rep12 pct_nohs_county pct_college_county med_white med_black pct_male_county"
global full_controls_var3 " pop_dens_county landarea_county 		pct_food_stamps_county med_rep16 med_rep12 pct_nohs_county pct_college_county med_white med_black pct_male_county"
global full_controls_var4 " pop_dens_county landarea_county age_imb					       med_rep16 med_rep12 pct_nohs_county pct_college_county med_white med_black pct_male_county"
global full_controls_var5 " pop_dens_county landarea_county age_imb pct_food_stamps_county 			 med_rep12 pct_nohs_county pct_college_county med_white med_black pct_male_county"
global full_controls_var6 " pop_dens_county landarea_county age_imb pct_food_stamps_county med_rep16		   pct_nohs_county pct_college_county med_white med_black pct_male_county"
global full_controls_var7 " pop_dens_county landarea_county age_imb pct_food_stamps_county med_rep16 med_rep12 				   pct_college_county med_white med_black pct_male_county"
global full_controls_var8 " pop_dens_county landarea_county age_imb pct_food_stamps_county med_rep16 med_rep12 pct_nohs_county 					  med_white med_black pct_male_county"
global full_controls_var9 " pop_dens_county landarea_county age_imb pct_food_stamps_county med_rep16 med_rep12 pct_nohs_county pct_college_county 		    med_black pct_male_county"
global full_controls_var10 "pop_dens_county landarea_county age_imb pct_food_stamps_county med_rep16 med_rep12 pct_nohs_county pct_college_county med_white 		  pct_male_county"
global full_controls_var11 "pop_dens_county landarea_county age_imb pct_food_stamps_county med_rep16 med_rep12 pct_nohs_county pct_college_county med_white med_black 				 "
									
* Reduced form
foreach cl in state_fips {
			foreach y in sd_sf_dist_fr_home {
				foreach controls_set in full_controls_var1 full_controls_var2 full_controls_var3 full_controls_var4 full_controls_var5 full_controls_var6 full_controls_var7 full_controls_var8 full_controls_var9 full_controls_var10 full_controls_var11 {				
					forvalues date=21946/22035 {
					if dow`date'[1]==0{
					global baseline "`y'_sun"
					}					
					if dow`date'[1]==1{
					global baseline "`y'_mon"
					}					
					if dow`date'[1]==2{
					global baseline "`y'_tue"
					}					
					if dow`date'[1]==3{
					global baseline "`y'_wed"
					}					
					if dow`date'[1]==4{
					global baseline "`y'_thu"
					}					
					if dow`date'[1]==5{
					global baseline "`y'_fri"
					}					
					if dow`date'[1]==6{
					global baseline "`y'_sat"
					}
					cap qui reghdfe `y'`date' fxnc [aweight=pop], absorb(state_fips one##c.($baseline ${`controls_set'} msnbc_rtg cnn_rtg)) cluster(`cl')
					qui lincom _b[fxnc]
					global coef_`controls_set'_`date'=r(estimate)
					global lb_`controls_set'_`date'=r(lb)
					global ub_`controls_set'_`date'=r(ub)
					macro drop baseline
					}
				matrix define matrix_coef_`controls_set'=(${coef_`controls_set'_21946} \ ${coef_`controls_set'_21947} \ ${coef_`controls_set'_21948} \ ${coef_`controls_set'_21949} \ ${coef_`controls_set'_21950} \ ${coef_`controls_set'_21951} \ ${coef_`controls_set'_21952} \ ${coef_`controls_set'_21953} \ ${coef_`controls_set'_21954} \ ${coef_`controls_set'_21955} \ ${coef_`controls_set'_21956} \ ${coef_`controls_set'_21957} \ ${coef_`controls_set'_21958} \ ${coef_`controls_set'_21959} \ ${coef_`controls_set'_21960} \ ${coef_`controls_set'_21961} \ ${coef_`controls_set'_21962} \ ${coef_`controls_set'_21963} \ ${coef_`controls_set'_21964} \ ${coef_`controls_set'_21965} \ ${coef_`controls_set'_21966} \ ${coef_`controls_set'_21967} \ ${coef_`controls_set'_21968} \ ${coef_`controls_set'_21969} \ ${coef_`controls_set'_21970} \ ${coef_`controls_set'_21971} \ ${coef_`controls_set'_21972} \ ${coef_`controls_set'_21973} \ ${coef_`controls_set'_21974} \ ${coef_`controls_set'_21975} \ ${coef_`controls_set'_21976} \ ${coef_`controls_set'_21977} \ ${coef_`controls_set'_21978} \ ${coef_`controls_set'_21979} \ ${coef_`controls_set'_21980} \ ${coef_`controls_set'_21981} \ ${coef_`controls_set'_21982} \ ${coef_`controls_set'_21983} \ ${coef_`controls_set'_21984} \ ${coef_`controls_set'_21985} \ ${coef_`controls_set'_21986} \ ${coef_`controls_set'_21987} \ ${coef_`controls_set'_21988} \ ${coef_`controls_set'_21989} \ ${coef_`controls_set'_21990} \ ${coef_`controls_set'_21991} \ ${coef_`controls_set'_21992} \ ${coef_`controls_set'_21993} \ ${coef_`controls_set'_21994} \ ${coef_`controls_set'_21995} \ ${coef_`controls_set'_21996} \ ${coef_`controls_set'_21997} \ ${coef_`controls_set'_21998} \ ${coef_`controls_set'_21999} \ ${coef_`controls_set'_22000} \ ${coef_`controls_set'_22001} \ ${coef_`controls_set'_22002} \ ${coef_`controls_set'_22003} \ ${coef_`controls_set'_22004} \ ${coef_`controls_set'_22005} \ ${coef_`controls_set'_22006} \ ${coef_`controls_set'_22007} \ ${coef_`controls_set'_22008} \ ${coef_`controls_set'_22009} \ ${coef_`controls_set'_22010} \ ${coef_`controls_set'_22011} \ ${coef_`controls_set'_22012} \ ${coef_`controls_set'_22013} \ ${coef_`controls_set'_22014} \ ${coef_`controls_set'_22015} \ ${coef_`controls_set'_22016} \ ${coef_`controls_set'_22017} \ ${coef_`controls_set'_22018} \ ${coef_`controls_set'_22019} \ ${coef_`controls_set'_22020} \ ${coef_`controls_set'_22021} \ ${coef_`controls_set'_22022} \ ${coef_`controls_set'_22023} \ ${coef_`controls_set'_22024} \ ${coef_`controls_set'_22025} \ ${coef_`controls_set'_22026} \ ${coef_`controls_set'_22027} \ ${coef_`controls_set'_22028} \ ${coef_`controls_set'_22029} \ ${coef_`controls_set'_22030} \ ${coef_`controls_set'_22031} \ ${coef_`controls_set'_22032} \ ${coef_`controls_set'_22033} \ ${coef_`controls_set'_22034} \ ${coef_`controls_set'_22035})
				matrix rownames matrix_coef_`controls_set'= _21946 _21947 _21948 _21949 _21950 _21951 _21952 _21953 _21954 _21955 _21956 _21957 _21958 _21959 _21960 _21961 _21962 _21963 _21964 _21965 _21966 _21967 _21968 _21969 _21970_21971 _21972 _21973 _21974 _21975 _21976 _21977 _21978 _21979 _21980 _21981 _21982 _21983 _21984 _21985 _21986 _21987 _21988 _21989 _21990 _21991 _21992 _21993 _21994 _21995 _21996 _21997 _21998 _21999 _22000 _22001 _22002 _22003 _22004 _22005 _22006 _22007 _22008 _22009 _22010 _22011 _22012 _22013 _22014 _22015 _22016 _22017 _22018 _22019 _22020 _22021 _22022 _22023 _22024 _22025 _22026 _22027 _22028 _22029 _22030 _22031 _22032 _22033 _22034 _22035
				matrix colnames matrix_coef_`controls_set'=b	
				matrix matrix_coef_`controls_set'=matrix_coef_`controls_set''
				
				matrix define matrix_ci_`controls_set'=(${lb_`controls_set'_21946} , ${lb_`controls_set'_21947} , ${lb_`controls_set'_21948} , ${lb_`controls_set'_21949} , ${lb_`controls_set'_21950} , ${lb_`controls_set'_21951} , ${lb_`controls_set'_21952} , ${lb_`controls_set'_21953} , ${lb_`controls_set'_21954} , ${lb_`controls_set'_21955} , ${lb_`controls_set'_21956} , ${lb_`controls_set'_21957} , ${lb_`controls_set'_21958} , ${lb_`controls_set'_21959} , ${lb_`controls_set'_21960} , ${lb_`controls_set'_21961} , ${lb_`controls_set'_21962} , ${lb_`controls_set'_21963} , ${lb_`controls_set'_21964} , ${lb_`controls_set'_21965} , ${lb_`controls_set'_21966} , ${lb_`controls_set'_21967} , ${lb_`controls_set'_21968} , ${lb_`controls_set'_21969} , ${lb_`controls_set'_21970} , ${lb_`controls_set'_21971} , ${lb_`controls_set'_21972} , ${lb_`controls_set'_21973} ,${lb_`controls_set'_21974} , ${lb_`controls_set'_21975} , ${lb_`controls_set'_21976} , ${lb_`controls_set'_21977} , ${lb_`controls_set'_21978} , ${lb_`controls_set'_21979} , ${lb_`controls_set'_21980} , ${lb_`controls_set'_21981} , ${lb_`controls_set'_21982} , ${lb_`controls_set'_21983} , ${lb_`controls_set'_21984} , ${lb_`controls_set'_21985} , ${lb_`controls_set'_21986} , ${lb_`controls_set'_21987} , ${lb_`controls_set'_21988} , ${lb_`controls_set'_21989} , ${lb_`controls_set'_21990} , ${lb_`controls_set'_21991} , ${lb_`controls_set'_21992} , ${lb_`controls_set'_21993} , ${lb_`controls_set'_21994} , ${lb_`controls_set'_21995} , ${lb_`controls_set'_21996} , ${lb_`controls_set'_21997} , ${lb_`controls_set'_21998} , ${lb_`controls_set'_21999} , ${lb_`controls_set'_22000} , ${lb_`controls_set'_22001} , ${lb_`controls_set'_22002} , ${lb_`controls_set'_22003} , ${lb_`controls_set'_22004} , ${lb_`controls_set'_22005} , ${lb_`controls_set'_22006} , ${lb_`controls_set'_22007} , ${lb_`controls_set'_22008} , ${lb_`controls_set'_22009} , ${lb_`controls_set'_22010} , ${lb_`controls_set'_22011} , ${lb_`controls_set'_22012} , ${lb_`controls_set'_22013} , ${lb_`controls_set'_22014} , ${lb_`controls_set'_22015} , ${lb_`controls_set'_22016} , ${lb_`controls_set'_22017} , ${lb_`controls_set'_22018} , ${lb_`controls_set'_22019} , ${lb_`controls_set'_22020} , ${lb_`controls_set'_22021} , ${lb_`controls_set'_22022} , ${lb_`controls_set'_22023} , ${lb_`controls_set'_22024} , ${lb_`controls_set'_22025} , ${lb_`controls_set'_22026} , ${lb_`controls_set'_22027} , ${lb_`controls_set'_22028} , ${lb_`controls_set'_22029} , ${lb_`controls_set'_22030} , ${lb_`controls_set'_22031} , ${lb_`controls_set'_22032} , ${lb_`controls_set'_22033} , ${lb_`controls_set'_22034} , ${lb_`controls_set'_22035} \ ${ub_`controls_set'_21946} , ${ub_`controls_set'_21947} , ${ub_`controls_set'_21948} , ${ub_`controls_set'_21949} , ${ub_`controls_set'_21950} , ${ub_`controls_set'_21951} , ${ub_`controls_set'_21952} , ${ub_`controls_set'_21953} , ${ub_`controls_set'_21954} , ${ub_`controls_set'_21955} , ${ub_`controls_set'_21956} , ${ub_`controls_set'_21957} , ${ub_`controls_set'_21958} , ${ub_`controls_set'_21959} , ${ub_`controls_set'_21960} , ${ub_`controls_set'_21961} , ${ub_`controls_set'_21962} , ${ub_`controls_set'_21963} , ${ub_`controls_set'_21964} , ${ub_`controls_set'_21965} , ${ub_`controls_set'_21966} , ${ub_`controls_set'_21967} , ${ub_`controls_set'_21968} , ${ub_`controls_set'_21969} , ${ub_`controls_set'_21970} , ${ub_`controls_set'_21971} , ${ub_`controls_set'_21972} , ${ub_`controls_set'_21973} ,${ub_`controls_set'_21974} , ${ub_`controls_set'_21975} , ${ub_`controls_set'_21976} , ${ub_`controls_set'_21977} , ${ub_`controls_set'_21978} , ${ub_`controls_set'_21979} ,${ub_`controls_set'_21980} , ${ub_`controls_set'_21981} , ${ub_`controls_set'_21982} , ${ub_`controls_set'_21983} , ${ub_`controls_set'_21984} , ${ub_`controls_set'_21985} , ${ub_`controls_set'_21986} , ${ub_`controls_set'_21987} , ${ub_`controls_set'_21988} , ${ub_`controls_set'_21989} , ${ub_`controls_set'_21990} , ${ub_`controls_set'_21991} , ${ub_`controls_set'_21992} , ${ub_`controls_set'_21993} , ${ub_`controls_set'_21994} , ${ub_`controls_set'_21995} , ${ub_`controls_set'_21996} , ${ub_`controls_set'_21997} , ${ub_`controls_set'_21998} , ${ub_`controls_set'_21999} , ${ub_`controls_set'_22000} , ${ub_`controls_set'_22001} , ${ub_`controls_set'_22002} , ${ub_`controls_set'_22003} , ${ub_`controls_set'_22004} , ${ub_`controls_set'_22005} , ${ub_`controls_set'_22006} , ${ub_`controls_set'_22007} , ${ub_`controls_set'_22008} , ${ub_`controls_set'_22009} , ${ub_`controls_set'_22010} , ${ub_`controls_set'_22011} , ${ub_`controls_set'_22012} , ${ub_`controls_set'_22013} , ${ub_`controls_set'_22014} , ${ub_`controls_set'_22015} , ${ub_`controls_set'_22016} , ${ub_`controls_set'_22017} , ${ub_`controls_set'_22018} , ${ub_`controls_set'_22019} , ${ub_`controls_set'_22020} , ${ub_`controls_set'_22021} , ${ub_`controls_set'_22022} , ${ub_`controls_set'_22023} , ${ub_`controls_set'_22024} , ${ub_`controls_set'_22025} , ${ub_`controls_set'_22026} , ${ub_`controls_set'_22027} , ${ub_`controls_set'_22028} , ${ub_`controls_set'_22029} , ${ub_`controls_set'_22030} , ${ub_`controls_set'_22031} , ${ub_`controls_set'_22032} , ${ub_`controls_set'_22033} , ${ub_`controls_set'_22034} , ${ub_`controls_set'_22035})
				}
			coefplot ///
			(matrix(matrix_coef_full_controls_var1),  ci(matrix_ci_full_controls_var1)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var2),  ci(matrix_ci_full_controls_var2)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var3),  ci(matrix_ci_full_controls_var3)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var4),  ci(matrix_ci_full_controls_var4)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var5),  ci(matrix_ci_full_controls_var5)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var6),  ci(matrix_ci_full_controls_var6)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var7),  ci(matrix_ci_full_controls_var7)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var8),  ci(matrix_ci_full_controls_var8)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var9),  ci(matrix_ci_full_controls_var9)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var10), ci(matrix_ci_full_controls_var10) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var11), ci(matrix_ci_full_controls_var11) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///			
			(matrix(matrix_coef_full_controls_var1),  ci(matrix_ci_full_controls_var1)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var2),  ci(matrix_ci_full_controls_var2)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var3),  ci(matrix_ci_full_controls_var3)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var4),  ci(matrix_ci_full_controls_var4)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var5),  ci(matrix_ci_full_controls_var5)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var6),  ci(matrix_ci_full_controls_var6)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var7),  ci(matrix_ci_full_controls_var7)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var8),  ci(matrix_ci_full_controls_var8)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var9),  ci(matrix_ci_full_controls_var9)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var10), ci(matrix_ci_full_controls_var10) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var11), ci(matrix_ci_full_controls_var11) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_full_controls_var1),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_full_controls_var2),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_full_controls_var3),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_full_controls_var4),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_full_controls_var5),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_full_controls_var6),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_full_controls_var7),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_full_controls_var8),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_full_controls_var9),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_full_controls_var10), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_full_controls_var11), noci color(maroon) mlwidth(thin)) ///
			, $general_options2 $x_line_multi nooffsets
			graph export "output/rf_distance_drop_one_regs.pdf", replace
			}
		*
		}
*	
}
*

* DROPPING INDIVIDUAL STATES
* figure s11			
foreach cl in state_fips {
* Reduced form
			foreach y in sd_sf_dist_fr_home {
				foreach state in 1 2 4 5 6 8 9 10 12 13 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 45 46 47 48 49 50 51 53 54 55 56 {				
					forvalues date=21946/22035 {	
					if dow`date'[1]==0{
					global baseline "`y'_sun"
					}					
					if dow`date'[1]==1{
					global baseline "`y'_mon"
					}					
					if dow`date'[1]==2{
					global baseline "`y'_tue"
					}					
					if dow`date'[1]==3{
					global baseline "`y'_wed"
					}					
					if dow`date'[1]==4{
					global baseline "`y'_thu"
					}					
					if dow`date'[1]==5{
					global baseline "`y'_fri"
					}					
					if dow`date'[1]==6{
					global baseline "`y'_sat"
					}
					cap qui reghdfe `y'`date' fxnc [aweight=pop] if state_fips!=`state', absorb(state_fips one##c.($baseline $full_controls1 msnbc_rtg cnn_rtg)) cluster(`cl')
					qui lincom _b[fxnc]
					global coef_`state'_`date'=r(estimate)
					global lb_`state'_`date'=r(lb)
					global ub_`state'_`date'=r(ub)
					macro drop baseline
					}
				matrix define matrix_coef_`state'=(${coef_`state'_21946} \ ${coef_`state'_21947} \ ${coef_`state'_21948} \ ${coef_`state'_21949} \ ${coef_`state'_21950} \ ${coef_`state'_21951} \ ${coef_`state'_21952} \ ${coef_`state'_21953} \ ${coef_`state'_21954} \ ${coef_`state'_21955} \ ${coef_`state'_21956} \ ${coef_`state'_21957} \ ${coef_`state'_21958} \ ${coef_`state'_21959} \ ${coef_`state'_21960} \ ${coef_`state'_21961} \ ${coef_`state'_21962} \ ${coef_`state'_21963} \ ${coef_`state'_21964} \ ${coef_`state'_21965} \ ${coef_`state'_21966} \ ${coef_`state'_21967} \ ${coef_`state'_21968} \ ${coef_`state'_21969} \ ${coef_`state'_21970} \ ${coef_`state'_21971} \ ${coef_`state'_21972} \ ${coef_`state'_21973} \ ${coef_`state'_21974} \ ${coef_`state'_21975} \ ${coef_`state'_21976} \ ${coef_`state'_21977} \ ${coef_`state'_21978} \ ${coef_`state'_21979} \ ${coef_`state'_21980} \ ${coef_`state'_21981} \ ${coef_`state'_21982} \ ${coef_`state'_21983} \ ${coef_`state'_21984} \ ${coef_`state'_21985} \ ${coef_`state'_21986} \ ${coef_`state'_21987} \ ${coef_`state'_21988} \ ${coef_`state'_21989} \ ${coef_`state'_21990} \ ${coef_`state'_21991} \ ${coef_`state'_21992} \ ${coef_`state'_21993} \ ${coef_`state'_21994} \ ${coef_`state'_21995} \ ${coef_`state'_21996} \ ${coef_`state'_21997} \ ${coef_`state'_21998} \ ${coef_`state'_21999} \ ${coef_`state'_22000} \ ${coef_`state'_22001} \ ${coef_`state'_22002} \ ${coef_`state'_22003} \ ${coef_`state'_22004} \ ${coef_`state'_22005} \ ${coef_`state'_22006} \ ${coef_`state'_22007} \ ${coef_`state'_22008} \ ${coef_`state'_22009} \ ${coef_`state'_22010} \ ${coef_`state'_22011} \ ${coef_`state'_22012} \ ${coef_`state'_22013} \ ${coef_`state'_22014} \ ${coef_`state'_22015} \ ${coef_`state'_22016} \ ${coef_`state'_22017} \ ${coef_`state'_22018} \ ${coef_`state'_22019} \ ${coef_`state'_22020} \ ${coef_`state'_22021} \ ${coef_`state'_22022} \ ${coef_`state'_22023} \ ${coef_`state'_22024} \ ${coef_`state'_22025} \ ${coef_`state'_22026} \ ${coef_`state'_22027} \ ${coef_`state'_22028} \ ${coef_`state'_22029} \ ${coef_`state'_22030} \ ${coef_`state'_22031} \ ${coef_`state'_22032} \ ${coef_`state'_22033} \ ${coef_`state'_22034} \ ${coef_`state'_22035})
				matrix rownames matrix_coef_`state'= _21946 _21947 _21948 _21949 _21950 _21951 _21952 _21953 _21954 _21955 _21956 _21957 _21958 _21959 _21960 _21961 _21962 _21963 _21964 _21965 _21966 _21967 _21968 _21969 _21970_21971 _21972 _21973 _21974 _21975 _21976 _21977 _21978 _21979 _21980 _21981 _21982 _21983 _21984 _21985 _21986 _21987 _21988 _21989 _21990 _21991 _21992 _21993 _21994 _21995 _21996 _21997 _21998 _21999 _22000 _22001 _22002 _22003 _22004 _22005 _22006 _22007 _22008 _22009 _22010 _22011 _22012 _22013 _22014 _22015 _22016 _22017 _22018 _22019 _22020 _22021 _22022 _22023 _22024 _22025 _22026 _22027 _22028 _22029 _22030 _22031 _22032 _22033 _22034 _22035
				matrix colnames matrix_coef_`state'=b	
				matrix matrix_coef_`state'=matrix_coef_`state''
				
				matrix define matrix_ci_`state'=(${lb_`state'_21946} , ${lb_`state'_21947} , ${lb_`state'_21948} , ${lb_`state'_21949} , ${lb_`state'_21950} , ${lb_`state'_21951} , ${lb_`state'_21952} , ${lb_`state'_21953} , ${lb_`state'_21954} , ${lb_`state'_21955} , ${lb_`state'_21956} , ${lb_`state'_21957} , ${lb_`state'_21958} , ${lb_`state'_21959} , ${lb_`state'_21960} , ${lb_`state'_21961} , ${lb_`state'_21962} , ${lb_`state'_21963} , ${lb_`state'_21964} , ${lb_`state'_21965} , ${lb_`state'_21966} , ${lb_`state'_21967} , ${lb_`state'_21968} , ${lb_`state'_21969} , ${lb_`state'_21970} , ${lb_`state'_21971} , ${lb_`state'_21972} , ${lb_`state'_21973} ,${lb_`state'_21974} , ${lb_`state'_21975} , ${lb_`state'_21976} , ${lb_`state'_21977} , ${lb_`state'_21978} , ${lb_`state'_21979} , ${lb_`state'_21980} , ${lb_`state'_21981} , ${lb_`state'_21982} , ${lb_`state'_21983} , ${lb_`state'_21984} , ${lb_`state'_21985} , ${lb_`state'_21986} , ${lb_`state'_21987} , ${lb_`state'_21988} , ${lb_`state'_21989} , ${lb_`state'_21990} , ${lb_`state'_21991} , ${lb_`state'_21992} , ${lb_`state'_21993} , ${lb_`state'_21994} , ${lb_`state'_21995} , ${lb_`state'_21996} , ${lb_`state'_21997} , ${lb_`state'_21998} , ${lb_`state'_21999} , ${lb_`state'_22000} , ${lb_`state'_22001} , ${lb_`state'_22002} , ${lb_`state'_22003} , ${lb_`state'_22004} , ${lb_`state'_22005} , ${lb_`state'_22006} , ${lb_`state'_22007} , ${lb_`state'_22008} , ${lb_`state'_22009} , ${lb_`state'_22010} , ${lb_`state'_22011} , ${lb_`state'_22012} , ${lb_`state'_22013} , ${lb_`state'_22014} , ${lb_`state'_22015} , ${lb_`state'_22016} , ${lb_`state'_22017} , ${lb_`state'_22018} , ${lb_`state'_22019} , ${lb_`state'_22020} , ${lb_`state'_22021} , ${lb_`state'_22022} , ${lb_`state'_22023} , ${lb_`state'_22024} , ${lb_`state'_22025} , ${lb_`state'_22026} , ${lb_`state'_22027} , ${lb_`state'_22028} , ${lb_`state'_22029} , ${lb_`state'_22030} , ${lb_`state'_22031} , ${lb_`state'_22032} , ${lb_`state'_22033} , ${lb_`state'_22034} , ${lb_`state'_22035} \ ${ub_`state'_21946} , ${ub_`state'_21947} , ${ub_`state'_21948} , ${ub_`state'_21949} , ${ub_`state'_21950} , ${ub_`state'_21951} , ${ub_`state'_21952} , ${ub_`state'_21953} , ${ub_`state'_21954} , ${ub_`state'_21955} , ${ub_`state'_21956} , ${ub_`state'_21957} , ${ub_`state'_21958} , ${ub_`state'_21959} , ${ub_`state'_21960} , ${ub_`state'_21961} , ${ub_`state'_21962} , ${ub_`state'_21963} , ${ub_`state'_21964} , ${ub_`state'_21965} , ${ub_`state'_21966} , ${ub_`state'_21967} , ${ub_`state'_21968} , ${ub_`state'_21969} , ${ub_`state'_21970} , ${ub_`state'_21971} , ${ub_`state'_21972} , ${ub_`state'_21973} ,${ub_`state'_21974} , ${ub_`state'_21975} , ${ub_`state'_21976} , ${ub_`state'_21977} , ${ub_`state'_21978} , ${ub_`state'_21979} ,${ub_`state'_21980} , ${ub_`state'_21981} , ${ub_`state'_21982} , ${ub_`state'_21983} , ${ub_`state'_21984} , ${ub_`state'_21985} , ${ub_`state'_21986} , ${ub_`state'_21987} , ${ub_`state'_21988} , ${ub_`state'_21989} , ${ub_`state'_21990} , ${ub_`state'_21991} , ${ub_`state'_21992} , ${ub_`state'_21993} , ${ub_`state'_21994} , ${ub_`state'_21995} , ${ub_`state'_21996} , ${ub_`state'_21997} , ${ub_`state'_21998} , ${ub_`state'_21999} , ${ub_`state'_22000} , ${ub_`state'_22001} , ${ub_`state'_22002} , ${ub_`state'_22003} , ${ub_`state'_22004} , ${ub_`state'_22005} , ${ub_`state'_22006} , ${ub_`state'_22007} , ${ub_`state'_22008} , ${ub_`state'_22009} , ${ub_`state'_22010} , ${ub_`state'_22011} , ${ub_`state'_22012} , ${ub_`state'_22013} , ${ub_`state'_22014} , ${ub_`state'_22015} , ${ub_`state'_22016} , ${ub_`state'_22017} , ${ub_`state'_22018} , ${ub_`state'_22019} , ${ub_`state'_22020} , ${ub_`state'_22021} , ${ub_`state'_22022} , ${ub_`state'_22023} , ${ub_`state'_22024} , ${ub_`state'_22025} , ${ub_`state'_22026} , ${ub_`state'_22027} , ${ub_`state'_22028} , ${ub_`state'_22029} , ${ub_`state'_22030} , ${ub_`state'_22031} , ${ub_`state'_22032} , ${ub_`state'_22033} , ${ub_`state'_22034} , ${ub_`state'_22035})
				}
			coefplot ///
			(matrix(matrix_coef_1),  ci(matrix_ci_1)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_2),  ci(matrix_ci_2)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_4),  ci(matrix_ci_4)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_5),  ci(matrix_ci_5)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_6),  ci(matrix_ci_6)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_8),  ci(matrix_ci_8)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_9),  ci(matrix_ci_9)  cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_10), ci(matrix_ci_10) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_12), ci(matrix_ci_12) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_13), ci(matrix_ci_13) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_15), ci(matrix_ci_15) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_16), ci(matrix_ci_16) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_17), ci(matrix_ci_17) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_18), ci(matrix_ci_18) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_19), ci(matrix_ci_19) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_20), ci(matrix_ci_20) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_21), ci(matrix_ci_21) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_22), ci(matrix_ci_22) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_23), ci(matrix_ci_23) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_24), ci(matrix_ci_24) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_25), ci(matrix_ci_25) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_26), ci(matrix_ci_26) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_27), ci(matrix_ci_27) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_28), ci(matrix_ci_28) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_29), ci(matrix_ci_29) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_30), ci(matrix_ci_30) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_31), ci(matrix_ci_31) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_32), ci(matrix_ci_32) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_33), ci(matrix_ci_33) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_34), ci(matrix_ci_34) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_35), ci(matrix_ci_35) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_36), ci(matrix_ci_36) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_37), ci(matrix_ci_37) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_38), ci(matrix_ci_38) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_39), ci(matrix_ci_39) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_40), ci(matrix_ci_40) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_41), ci(matrix_ci_41) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_42), ci(matrix_ci_42) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_44), ci(matrix_ci_44) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_45), ci(matrix_ci_45) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_46), ci(matrix_ci_46) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_47), ci(matrix_ci_47) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_48), ci(matrix_ci_48) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_49), ci(matrix_ci_49) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_50), ci(matrix_ci_50) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_51), ci(matrix_ci_51) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_53), ci(matrix_ci_53) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_54), ci(matrix_ci_54) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_55), ci(matrix_ci_55) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_56), ci(matrix_ci_56) cirecast(rarea) ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef_1),  ci(matrix_ci_1)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_2),  ci(matrix_ci_2)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_4),  ci(matrix_ci_4)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_5),  ci(matrix_ci_5)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_6),  ci(matrix_ci_6)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_8),  ci(matrix_ci_8)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_9),  ci(matrix_ci_9)  cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_10), ci(matrix_ci_10) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_12), ci(matrix_ci_12) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_13), ci(matrix_ci_13) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_15), ci(matrix_ci_15) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_16), ci(matrix_ci_16) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_17), ci(matrix_ci_17) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_18), ci(matrix_ci_18) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_19), ci(matrix_ci_19) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_20), ci(matrix_ci_20) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_21), ci(matrix_ci_21) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_22), ci(matrix_ci_22) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_23), ci(matrix_ci_23) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_24), ci(matrix_ci_24) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_25), ci(matrix_ci_25) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_26), ci(matrix_ci_26) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_27), ci(matrix_ci_27) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_28), ci(matrix_ci_28) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_29), ci(matrix_ci_29) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_30), ci(matrix_ci_30) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_31), ci(matrix_ci_31) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_32), ci(matrix_ci_32) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_33), ci(matrix_ci_33) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_34), ci(matrix_ci_34) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_35), ci(matrix_ci_35) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_36), ci(matrix_ci_36) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_37), ci(matrix_ci_37) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_38), ci(matrix_ci_38) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_39), ci(matrix_ci_39) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_40), ci(matrix_ci_40) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_41), ci(matrix_ci_41) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_42), ci(matrix_ci_42) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_44), ci(matrix_ci_44) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_45), ci(matrix_ci_45) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_46), ci(matrix_ci_46) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_47), ci(matrix_ci_47) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_48), ci(matrix_ci_48) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_49), ci(matrix_ci_49) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_50), ci(matrix_ci_50) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_51), ci(matrix_ci_51) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_53), ci(matrix_ci_53) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_54), ci(matrix_ci_54) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_55), ci(matrix_ci_55) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_56), ci(matrix_ci_56) cirecast(rline) ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef_1),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_1),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_2),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_4),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_5),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_6),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_8),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_9),  noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_10), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_12), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_13), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_15), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_16), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_17), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_18), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_19), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_20), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_21), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_22), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_23), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_24), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_25), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_26), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_27), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_28), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_29), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_30), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_31), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_32), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_33), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_34), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_35), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_36), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_37), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_38), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_39), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_40), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_41), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_42), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_44), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_45), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_46), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_47), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_48), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_49), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_50), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_51), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_53), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_54), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_55), noci color(maroon) mlwidth(thin)) ///
			(matrix(matrix_coef_56), noci color(maroon) mlwidth(thin)) ///
			, $general_options2 $x_line_multi nooffsets
			graph export "output/rf_drop_state_regs.pdf", replace
			}
		*
		}
*

* DROPPING JANUARY BASELINE
* figure s12
global rc_safegraph=1
if ${rc_safegraph}==1 {			
	foreach cl in state_fips {
		foreach network in fxnc {
		* 2SLS
			foreach y of global outcomes_pick {
			cap drop _est*
			eststo clear
				forvalues date=21946/22035 {	
				cap qui ivreghdfe `y'`date' (`network'_rtg= `network') [aweight=pop], absorb(state_fips one##c.($full_controls1 ${other_rtgs_`network'})) cluster(`cl')
				cap eststo _`date'
				}
			coefplot $dates_coefplot_mobility_sf, $general_options $x_line_sf keep(`network'_rtg) 
			graph export "output/2016_nobase_`network'_censuscontrols1_`cl'_`y'.pdf", replace
			}
		}
	}
}
*	

* ACS 2019 CONTROLS
* figure s16, table s3
global safegraph_acs=1
if ${safegraph_acs}==1 {
foreach cl in state_fips {
	foreach network in fxnc {
			foreach y in sd_sf_dist_fr_home sd_sf_median_nohome_time  {
				cap drop _est*
				eststo clear
					forvalues date=21946/22035 {
					if dow`date'[1]==0{
					global baseline "`y'_sun"
					}					
					if dow`date'[1]==1{
					global baseline "`y'_mon"
					}					
					if dow`date'[1]==2{
					global baseline "`y'_tue"
					}					
					if dow`date'[1]==3{
					global baseline "`y'_wed"
					}					
					if dow`date'[1]==4{
					global baseline "`y'_thu"
					}					
					if dow`date'[1]==5{
					global baseline "`y'_fri"
					}					
					if dow`date'[1]==6{
					global baseline "`y'_sat"
					}

					reghdfe `y'`date' `network' [aweight=pop], absorb(state_fips one##c.(acs_medical acs_retail acs_agri_farming_nat acs_manual_industrial acs_transport $baseline $full_controls1 ${other_rtgs_`network'})) cluster(`cl')
					cap eststo _`date'
					}
				coefplot $dates_coefplot_mobility_sf, $general_options_reduced $options $x_line_sf keep(`network') 
				graph export "output/acs_controls_2016_`network'_censuscontrols1_`cl'_`y'.pdf", replace
				}	
		*
	}
}

foreach variable in acs_medical acs_retail acs_agri_farming_nat acs_manual_industrial acs_transport {
	foreach network in fxnc  {
	reghdfe `variable' `network' [aweight=pop], absorb(state_fips one##c.($full_controls1 ${other_rtgs_`network'})) cluster(state_fips) 
	}
}

*				
}
*

* SPLITTING SAMPLE BY KEY DEMOGRAPHICS
* figure s17, figure s19
global heterogeneity=1
if ${heterogeneity}==1 {
*
gen food_stamps=pct_food_stamps_county
gen nohs=pct_nohs_county
global dem_touse "food_stamps nohs"

foreach var of global dem_touse {
egen med_`var'=median(pct_`var'_county)
}

foreach var in food_stamps nohs {
gen  above_med_`var'=pct_`var'_county>med_`var' if pct_`var'_county!=.
gen  below_med_`var'=pct_`var'_county<med_`var' if pct_`var'_county!=.
}

	foreach dem in food_stamps nohs  { 
	foreach cl in state_fips {
		foreach network in fxnc {
				foreach y in sd_sf_dist_fr_home sd_sf_median_nohome_time  {
					cap drop _est*
					eststo clear
						forvalues date=21946/22035 {
						if dow`date'[1]==0{
						global baseline "`y'_sun"
						}					
						if dow`date'[1]==1{
						global baseline "`y'_mon"
						}					
						if dow`date'[1]==2{
						global baseline "`y'_tue"
						}					
						if dow`date'[1]==3{
						global baseline "`y'_wed"
						}					
						if dow`date'[1]==4{
						global baseline "`y'_thu"
						}					
						if dow`date'[1]==5{
						global baseline "`y'_fri"
						}					
						if dow`date'[1]==6{
						global baseline "`y'_sat"
						}

						qui reghdfe `y'`date' `network' if above_med_`dem'==1 [aweight=pop], absorb(state_fips one##c.($baseline $full_controls1  ${other_rtgs_`network'})) cluster(`cl')
						cap eststo _`date'
						}
					coefplot $dates_coefplot_mobility_sf, $general_options_reduced $options $x_line_sf keep(`network') 
					graph export "output/above_med_`dem'_2016_`network'_censuscontrols1_`cl'_`y'.pdf", replace
					}	
			*
		foreach y in sd_sf_dist_fr_home sd_sf_median_nohome_time  {
					cap drop _est*
					eststo clear
						forvalues date=21946/22035 {
						if dow`date'[1]==0{
						global baseline "`y'_sun"
						}					
						if dow`date'[1]==1{
						global baseline "`y'_mon"
						}					
						if dow`date'[1]==2{
						global baseline "`y'_tue"
						}					
						if dow`date'[1]==3{
						global baseline "`y'_wed"
						}					
						if dow`date'[1]==4{
						global baseline "`y'_thu"
						}					
						if dow`date'[1]==5{
						global baseline "`y'_fri"
						}					
						if dow`date'[1]==6{
						global baseline "`y'_sat"
						}
						qui reghdfe `y'`date' `network' if below_med_`dem'==1 [aweight=pop], absorb(state_fips one##c.($baseline $full_controls1  ${other_rtgs_`network'})) cluster(`cl')
						cap eststo _`date'
						}
					macro drop options
					coefplot $dates_coefplot_mobility_sf, $general_options_reduced $options $x_line_sf keep(`network') 
					graph export "output/below_med_`dem'_2016_`network'_censuscontrols1_`cl'_`y'.pdf", replace
					}	
			*
			
		}
	}
	*
	}

}
*

* CNN / MSNBC 
* figure s21, figure s22
foreach cl in state_fips {
	foreach network in cnn msnbc {
	* OLS
			foreach y of global outcomes_pick {
				cap drop _est*
				eststo clear
					forvalues date=21946/22035 {
					if dow`date'[1]==0{
					global baseline "`y'_sun"
					}					
					if dow`date'[1]==1{
					global baseline "`y'_mon"
					}					
					if dow`date'[1]==2{
					global baseline "`y'_tue"
					}					
					if dow`date'[1]==3{
					global baseline "`y'_wed"
					}					
					if dow`date'[1]==4{
					global baseline "`y'_thu"
					}					
					if dow`date'[1]==5{
					global baseline "`y'_fri"
					}					
					if dow`date'[1]==6{
					global baseline "`y'_sat"
					}

					cap qui reghdfe `y'`date' `network'_rtg [aweight=pop], absorb(state_fips one##c.($baseline $full_controls1 $time_death $time_case ${other_rtgs_`network'})) cluster(`cl')
					cap eststo _`date'
					}
				coefplot $dates_coefplot_mobility_sf, $general_options_ols $x_line_sf keep(`network'_rtg) 
				graph export "output/ols_2016_`network'_network_check_censuscontrols1_`cl'_`y'.pdf", replace
				}
	*
	* 2SLS
			foreach y of global outcomes_pick {
				cap drop _est*
				eststo clear
					forvalues date=21946/22035 {
					if dow`date'[1]==0{
					global baseline "`y'_sun"
					}					
					if dow`date'[1]==1{
					global baseline "`y'_mon"
					}					
					if dow`date'[1]==2{
					global baseline "`y'_tue"
					}					
					if dow`date'[1]==3{
					global baseline "`y'_wed"
					}					
					if dow`date'[1]==4{
					global baseline "`y'_thu"
					}					
					if dow`date'[1]==5{
					global baseline "`y'_fri"
					}					
					if dow`date'[1]==6{
					global baseline "`y'_sat"
					}
					cap qui ivreghdfe `y'`date' (`network'_rtg= `network') [aweight=pop], absorb(state_fips one##c.($baseline $full_controls1 ${other_rtgs_`network'})) cluster(`cl')
					cap eststo _`date'
					}
				coefplot $dates_coefplot_mobility_sf, $general_options $x_line_sf keep(`network'_rtg) 
				graph export "output/2sls_2016_`network'_network_check_censuscontrols1_`cl'_`y'.pdf", replace
				}
	*
	}
}
*	

* HEALTH OUTCOMES 
* figure s23, figure s24, table s7, table s8, 
global corona=1
if ${corona}==1 {
preserve
* Notes: first period is not plotted because its small sample size noise would make the rest of the graph unreadeble 
	cap drop id
	gen id=_n
	forvalues date=21946/21973 {
	replace ratio_deaths_pop`date'=0.00005 if id==1
	replace ratio_cases_pop`date'=0.00005 if id==1
	replace st_incr_cases_7_`date'=0.00005 if id==1
	replace st_incr_deaths_7_`date'=0.00005 if id==1
	}
foreach cl in state_fips {
		foreach network in fxnc {
			foreach y of global outcomes_pick1 {
			if inlist("`y'","ratio_cases_pop") {
			global options "$general_options_ratioc"
			}
			if inlist("`y'","ratio_deaths_pop") {
			global options "$general_options_ratiod"
			}
			if inlist("`y'","st_incr_cases_7_","incr_cases_7_") {
			global options "$general_options_incrc"
			}
			if inlist("`y'","st_incr_deaths_7_","incr_deaths_7_") {
			global options "$general_options_incrd"
			}
				cap drop _est*
				eststo clear
					forvalues date=21946/22035 {				
					cap qui ivreghdfe `y'`date' (`network'_rtg=`network') [aweight=pop], absorb(state_fips one##c.($full_controls1 ${other_rtgs_`network'})) cluster(`cl')
					cap eststo _`date'
					}
				coefplot (_21946, color(white%1) ciopts(color(white%1))) (_21947, color(white%1) ciopts(color(white%1))) (_21948, color(white%1) ciopts(color(white%1))) (_21949, color(white%1) ciopts(color(white%1))) (_21950, color(white%1) ciopts(color(white%1))) (_21951, color(white%1) ciopts(color(white%1))) (_21952, color(white%1) ciopts(color(white%1))) (_21953, color(white%1) ciopts(color(white%1))) (_21954, color(white%1) ciopts(color(white%1))) (_21955, color(white%1) ciopts(color(white%1))) (_21956, color(white%1) ciopts(color(white%1))) (_21957, color(white%1) ciopts(color(white%1))) (_21958, color(white%1) ciopts(color(white%1))) (_21959, color(white%1) ciopts(color(white%1))) (_21960, color(white%1) ciopts(color(white%1))) (_21961, color(white%1) ciopts(color(white%1))) (_21962, color(white%1) ciopts(color(white%1))) (_21963, color(white%1) ciopts(color(white%1))) (_21964, color(white%1) ciopts(color(white%1))) (_21965, color(white%1) ciopts(color(white%1))) (_21966, color(white%1) ciopts(color(white%1))) (_21967, color(white%1) ciopts(color(white%1))) (_21968, color(white%1) ciopts(color(white%1))) (_21969, color(white%1) ciopts(color(white%1))) (_21970, color(white%1) ciopts(color(white%1))) (_21971, color(white%1) ciopts(color(white%1))) (_21972, color(white%1) ciopts(color(white%1))) (_21973, color(white%1) ciopts(color(white%1))) _21974 _21975 _21976 _21977 _21978 _21979 _21980 _21981 _21982 _21983 _21984 _21985 _21986 _21987 _21988 _21989 _21990 _21991 _21992 _21993 _21994 _21995 _21996 _21997 _21998 _21999 _22000 _22001 _22002 _22003 _22004 _22005 _22006 _22007 _22008 _22009 _22010 _22011 _22012 _22013 _22014 _22015 _22016 _22017 _22018 _22019 _22020 _22021 _22022 _22023 _22024 _22025 _22026 _22027 _22028 _22029 _22030 _22031 _22032 _22033 _22034 _22035, $options $x_line_sf keep(`network'_rtg) 
				macro drop options
				graph export "output/2016_`network'_censuscontrols1_`cl'_`y'.pdf", replace
				}	
		*
		}
	}
restore	
*
}
*

* HEALTH OUTCOMES WITH MAY AND JUNE
* figure s25
global corona_june=1
if ${corona_june}==1 {
	
global x_line_june "xline(0.511 1.492, lpattern(dot) lwidth(1) lcolor(gray)) xlabel(0.511 "February 1st" 1.492 "June 30th")"

*
preserve
	cap drop id
	gen id=_n
	forvalues date=21946/21973 {
	replace ratio_deaths_pop`date'=0.00005 if id==1
	replace ratio_cases_pop`date'=0.00005 if id==1
	replace st_incr_cases_7_`date'=0.00005 if id==1
	replace st_incr_deaths_7_`date'=0.00005 if id==1
	}
	foreach cl in state_fips {
		foreach network in fxnc {
		* Main outcomes iv
				foreach y of global outcomes_pick1 {
				if inlist("`y'","ratio_cases_pop") {
				global options "$general_options_ratioc"
				}
				if inlist("`y'","ratio_deaths_pop") {
				global options "$general_options_ratiod"
				}
				if inlist("`y'","st_incr_cases_7_") {
				global options "$general_options_incrc"
				}
				if inlist("`y'","st_incr_deaths_7_") {
				global options "$general_options_incrd"
				}
					cap drop _est*
					eststo clear
						forvalues date=21946/22096 {	
						cap qui ivreghdfe `y'`date' (`network'_rtg=`network') [aweight=pop], absorb(state_fips one##c.($full_controls1  ${other_rtgs_`network'})) cluster(`cl')
						cap eststo _`date'
						}
					coefplot (_21946, color(white%1) ciopts(color(white%1))) (_21947, color(white%1) ciopts(color(white%1))) (_21948, color(white%1) ciopts(color(white%1))) (_21949, color(white%1) ciopts(color(white%1))) (_21950, color(white%1) ciopts(color(white%1))) (_21951, color(white%1) ciopts(color(white%1))) (_21952, color(white%1) ciopts(color(white%1))) (_21953, color(white%1) ciopts(color(white%1))) (_21954, color(white%1) ciopts(color(white%1))) (_21955, color(white%1) ciopts(color(white%1))) (_21956, color(white%1) ciopts(color(white%1))) (_21957, color(white%1) ciopts(color(white%1))) (_21958, color(white%1) ciopts(color(white%1))) (_21959, color(white%1) ciopts(color(white%1))) (_21960, color(white%1) ciopts(color(white%1))) (_21961, color(white%1) ciopts(color(white%1))) (_21962, color(white%1) ciopts(color(white%1))) (_21963, color(white%1) ciopts(color(white%1))) (_21964, color(white%1) ciopts(color(white%1))) (_21965, color(white%1) ciopts(color(white%1))) (_21966, color(white%1) ciopts(color(white%1))) (_21967, color(white%1) ciopts(color(white%1))) (_21968, color(white%1) ciopts(color(white%1))) (_21969, color(white%1) ciopts(color(white%1))) (_21970, color(white%1) ciopts(color(white%1))) (_21971, color(white%1) ciopts(color(white%1))) (_21972, color(white%1) ciopts(color(white%1))) (_21973, color(white%1) ciopts(color(white%1))) _21974 _21975 _21976 _21977 _21978 _21979 _21980 _21981 _21982 _21983 _21984 _21985 _21986 _21987 _21988 _21989 _21990 _21991 _21992 _21993 _21994 _21995 _21996 _21997 _21998 _21999 _22000 _22001 _22002 _22003 _22004 _22005 _22006 _22007 _22008 _22009 _22010 _22011 _22012 _22013 _22014 _22015 _22016 _22017 _22018 _22019 _22020 _22021 _22022 _22023 _22024 _22025 _22026 _22027 _22028 _22029 _22030 _22031 _22032 _22033 _22034 _22035 _22036 _22037 _22038 _22039 _22040 _22041 _22042 _22043 _22044 _22045 _22046 _22047 _22048 _22049 _22050 _22051 _22052 _22053 _22054 _22055 _22056 _22057 _22058 _22059 _22060 _22061 _22062 _22063 _22064 _22065 _22066 _22067 _22068 _22069 _22070 _22071 _22072 _22073 _22074 _22075 _22076 _22077 _22078 _22079 _22080 _22081 _22082 _22083 _22084 _22085 _22086 _22087 _22088 _22089 _22090 _22091 _22092 _22093 _22094 _22095 _22096, $options $x_line_june keep(`network'_rtg) 
					macro drop options
					graph export "output/june_2016_`network'_censuscontrols1_`cl'_`y'.pdf", replace
					}
		*		
		}
	}
restore	
*

*				
}
*

* SEASONAL FLU
* figure s26
global seasonal_flu=1
if ${seasonal_flu}==1 {
preserve
replace fxnc=abs(fxnc)
foreach var in deaths_seas_flu2007_2009 deaths_seas_flu2010_2013 deaths_seas_flu2013_2015 deaths_seas_flu2016_2018 {
di fxnc[1]
binscatterhist 	`var' fxnc [aweight=pop], absorb(state_fips) controls($full_controls1 ${other_rtgs_fxnc}) cluster(state_fips) nquantiles(25) sample  coefficient(0.001)
* legacy(graphregion(margin(3 6 3 6)) play(y_title_coefplot_no_legenda) graphregion(fcolor(white))  legend(off) ytitle("Effect on Seasonal Flu (RF)") xsize(8)) /* depending on binscatterhist version */

graph export "output/`var'_fxnc_censuscontrols1_state_fips.pdf", replace
}
restore
}
* 

* RC POLYNOMIALS AND INTERACTIONS (elections controls) 
* figure s27
global rc_polynomials_interactions_ec_m=1
if ${rc_polynomials_interactions_ec_m}==1 {

foreach check_var in med_rep12 med_rep16 sh_rep2012 sh_rep2016 pres_share_rep1996{
cap gen `check_var'_2=`check_var'^2	
cap gen `check_var'_3=`check_var'^3	
cap gen `check_var'_fxnc=`check_var'*fxnc
}
	foreach cl in state_fips {
		foreach network in fxnc {
				foreach y in sd_sf_dist_fr_home sd_sf_median_nohome_time  {
					cap drop _est*
					eststo clear
						forvalues date=21946/22035 {	
						if dow`date'[1]==0{
						global baseline "`y'_sun"
						}					
						if dow`date'[1]==1{
						global baseline "`y'_mon"
						}					
						if dow`date'[1]==2{
						global baseline "`y'_tue"
						}					
						if dow`date'[1]==3{
						global baseline "`y'_wed"
						}					
						if dow`date'[1]==4{
						global baseline "`y'_thu"
						}					
						if dow`date'[1]==5{
						global baseline "`y'_fri"
						}					
						if dow`date'[1]==6{
						global baseline "`y'_sat"
						}

						cap qui reghdfe `y'`date' `network' [aweight=pop], absorb(state_fips one##c.(sh_rep2012_2 sh_rep2016_2 sh_rep2012_3 sh_rep2016_3 pres_share_rep1996_2 pres_share_rep1996_3 $baseline $full_controls1 ${other_rtgs_`network'})) cluster(`cl')
						cap eststo _`date'
						}
					coefplot $dates_coefplot_mobility_sf, $general_options_reduced $options $x_line_sf keep(`network') 
					graph export "output/control_controls_2016_`network'_censuscontrols1_`cl'_`y'.pdf", replace
					}	
			*
		}
	}
*
	foreach cl in state_fips {
		foreach network in fxnc {
		* Main outcomes REDUCED
				foreach y in sd_sf_dist_fr_home sd_sf_median_nohome_time  {
					cap drop _est*
					eststo clear
						forvalues date=21946/22035 {
						if dow`date'[1]==0{
						global baseline "`y'_sun"
						}					
						if dow`date'[1]==1{
						global baseline "`y'_mon"
						}					
						if dow`date'[1]==2{
						global baseline "`y'_tue"
						}					
						if dow`date'[1]==3{
						global baseline "`y'_wed"
						}					
						if dow`date'[1]==4{
						global baseline "`y'_thu"
						}					
						if dow`date'[1]==5{
						global baseline "`y'_fri"
						}					
						if dow`date'[1]==6{
						global baseline "`y'_sat"
						}

						cap qui reghdfe `y'`date' `network' [aweight=pop], absorb(state_fips one##c.(sh_rep2012_fxnc sh_rep2016_fxnc pres_share_rep1996_fxnc $baseline $full_controls1 ${other_rtgs_`network'})) cluster(`cl')
						cap eststo _`date'
						}
					coefplot $dates_coefplot_mobility_sf, $general_options_reduced $options $x_line_sf keep(`network') 
					graph export "output/control_interactions_2016_`network'_censuscontrols1_`cl'_`y'.pdf", replace
					}	
			*
		}
	}
*
}
*	

* CHECK ON GALLUP DATA (ideology and party controls)
* figure s28, figure s29, figure s30
global safegraph_gallup=1
if ${safegraph_gallup}==1 {
cap gen gallup_rep_sh_2012_2019_fxnc = fxnc*gallup_rep_sh_2012_2019
cap gen gallup_rep_sh_2016_2019_fxnc = fxnc*gallup_rep_sh_2016_2019

cap gen gallup_cons_sh_2012_2019_fxnc = fxnc*gallup_cons_sh_2012_2019
cap gen gallup_cons_sh_2016_2019_fxnc = fxnc*gallup_cons_sh_2016_2019

foreach cl in state_fips {
	foreach network in fxnc {
		foreach y in sd_sf_dist_fr_home sd_sf_median_nohome_time  {
				cap drop _est*
				eststo clear
					forvalues date=21946/22035 {

					if dow`date'[1]==0{
					global baseline "`y'_sun"
					}					
					if dow`date'[1]==1{
					global baseline "`y'_mon"
					}					
					if dow`date'[1]==2{
					global baseline "`y'_tue"
					}					
					if dow`date'[1]==3{
					global baseline "`y'_wed"
					}					
					if dow`date'[1]==4{
					global baseline "`y'_thu"
					}					
					if dow`date'[1]==5{
					global baseline "`y'_fri"
					}					
					if dow`date'[1]==6{
					global baseline "`y'_sat"
					}

					qui reghdfe `y'`date' `network' [aweight=pop], absorb(state_fips one##c.(gallup_rep_sh_2016_2019 gallup_cons_sh_2016_2019 $baseline $full_controls1 ${other_rtgs_`network'})) cluster(`cl')
					cap eststo _`date'
					}
				coefplot $dates_coefplot_mobility_sf, $general_options_reduced $options $x_line_sf keep(`network') 
				graph export "output/controls_gallup2016-2019_2016_`network'_censuscontrols1_`cl'_`y'.pdf", replace
				}	
		*
			foreach y in sd_sf_dist_fr_home sd_sf_median_nohome_time  {
				cap drop _est*
				eststo clear
					forvalues date=21946/22035 {
					if dow`date'[1]==0{
					global baseline "`y'_sun"
					}					
					if dow`date'[1]==1{
					global baseline "`y'_mon"
					}					
					if dow`date'[1]==2{
					global baseline "`y'_tue"
					}					
					if dow`date'[1]==3{
					global baseline "`y'_wed"
					}					
					if dow`date'[1]==4{
					global baseline "`y'_thu"
					}					
					if dow`date'[1]==5{
					global baseline "`y'_fri"
					}					
					if dow`date'[1]==6{
					global baseline "`y'_sat"
					}
					qui reghdfe `y'`date' `network' [aweight=pop], absorb(state_fips one##c.(gallup_rep_sh_2012_2019 gallup_cons_sh_2012_2019 $baseline $full_controls1 ${other_rtgs_`network'})) cluster(`cl')
					cap eststo _`date'
					}
				coefplot $dates_coefplot_mobility_sf, $general_options_reduced $options $x_line_sf keep(`network') 
				graph export "output/controls_gallup2012-2019_2016_`network'_censuscontrols1_`cl'_`y'.pdf", replace
				}	
		*
			foreach y in sd_sf_dist_fr_home sd_sf_median_nohome_time  {
				cap drop _est*
				eststo clear
					forvalues date=21946/22035 {
					if dow`date'[1]==0{
					global baseline "`y'_sun"
					}					
					if dow`date'[1]==1{
					global baseline "`y'_mon"
					}					
					if dow`date'[1]==2{
					global baseline "`y'_tue"
					}					
					if dow`date'[1]==3{
					global baseline "`y'_wed"
					}					
					if dow`date'[1]==4{
					global baseline "`y'_thu"
					}					
					if dow`date'[1]==5{
					global baseline "`y'_fri"
					}					
					if dow`date'[1]==6{
					global baseline "`y'_sat"
					}
					qui reghdfe `y'`date' `network' [aweight=pop], absorb(state_fips one##c.(gallup_rep_sh_2016_2019_fxnc gallup_cons_sh_2016_2019_fxnc $baseline $full_controls1 ${other_rtgs_`network'})) cluster(`cl')
					cap eststo _`date'
					}
				coefplot $dates_coefplot_mobility_sf, $general_options_reduced $options $x_line_sf keep(`network') 
				graph export "output/interactions_gallup2016-2019_2016_`network'_censuscontrols1_`cl'_`y'.pdf", replace
				}	
		*
			foreach y in sd_sf_dist_fr_home sd_sf_median_nohome_time  {
				cap drop _est*
				eststo clear
					forvalues date=21946/22035 {	
					if dow`date'[1]==0{
					global baseline "`y'_sun"
					}					
					if dow`date'[1]==1{
					global baseline "`y'_mon"
					}					
					if dow`date'[1]==2{
					global baseline "`y'_tue"
					}					
					if dow`date'[1]==3{
					global baseline "`y'_wed"
					}					
					if dow`date'[1]==4{
					global baseline "`y'_thu"
					}					
					if dow`date'[1]==5{
					global baseline "`y'_fri"
					}					
					if dow`date'[1]==6{
					global baseline "`y'_sat"
					}
					qui reghdfe `y'`date' `network' [aweight=pop], absorb(state_fips one##c.(gallup_rep_sh_2012_2019_fxnc gallup_cons_sh_2012_2019_fxnc $baseline $full_controls1 ${other_rtgs_`network'})) cluster(`cl')
					cap eststo _`date'
					}
				coefplot $dates_coefplot_mobility_sf, $general_options_reduced $options $x_line_sf keep(`network') 
				graph export "output/interactions_gallup2012-2019_2016_`network'_censuscontrols1_`cl'_`y'.pdf", replace
				}	
		*
		
	}
}

foreach variable in gallup_rep_sh_2012_2019 gallup_cons_sh_2012_2019 gallup_rep_sh_2016_2019 gallup_cons_sh_2016_2019 {
	foreach network in fxnc  {
	reghdfe `variable' `network' [aweight=pop], absorb(state_fips one##c.($full_controls1 ${other_rtgs_`network'})) cluster(state_fips) 
	binscatterhist 	`variable' `network' [aweight=pop], coef(0.00001) absorb(state_fips) cluster(state_fips) controls($full_controls1 ${other_rtgs_`network'}) nquantiles(19)  graphregion(fcolor(white))  legend(off) ytitle("Gallup Measure") xtitle("Fox News Channel Position (Standardized)")  color(teal) lcolor(maroon) 
	graph export "output/gallup_`variable'_`network'_censuscontrols1_state_fips.pdf", replace
	}
}

*				
}
*

* SPLITTING BY 1996 PARTISANSHIP
* figure s31
global safegraph_repstronghold=1
if ${safegraph_repstronghold}==1 {
	
cap gen rep_stronghold=pres_share_rep1996>0.5
foreach cl in state_fips {
	foreach network in fxnc {
			foreach y in sd_sf_dist_fr_home sd_sf_median_nohome_time  {
				cap drop _est*
				eststo clear
					forvalues date=21946/22035 {
					if dow`date'[1]==0{
					global baseline "`y'_sun"
					}					
					if dow`date'[1]==1{
					global baseline "`y'_mon"
					}					
					if dow`date'[1]==2{
					global baseline "`y'_tue"
					}					
					if dow`date'[1]==3{
					global baseline "`y'_wed"
					}					
					if dow`date'[1]==4{
					global baseline "`y'_thu"
					}					
					if dow`date'[1]==5{
					global baseline "`y'_fri"
					}					
					if dow`date'[1]==6{
					global baseline "`y'_sat"
					}

					qui reghdfe `y'`date' `network' if rep_stronghold==1 [aweight=pop], absorb(state_fips one##c.($baseline $full_controls1 ${other_rtgs_`network'})) cluster(`cl')
					cap eststo _`date'
					}
				macro drop options
				coefplot $dates_coefplot_mobility_sf, $general_options_reduced $options $x_line_sf keep(`network') 
				graph export "output/rep_stronghold1996_2016_`network'_censuscontrols1_`cl'_`y'.pdf", replace
				}	
		*
			foreach y in sd_sf_dist_fr_home sd_sf_median_nohome_time  {
				cap drop _est*
				eststo clear
					forvalues date=21946/22035 {
					if dow`date'[1]==0{
					global baseline "`y'_sun"
					}					
					if dow`date'[1]==1{
					global baseline "`y'_mon"
					}					
					if dow`date'[1]==2{
					global baseline "`y'_tue"
					}					
					if dow`date'[1]==3{
					global baseline "`y'_wed"
					}					
					if dow`date'[1]==4{
					global baseline "`y'_thu"
					}					
					if dow`date'[1]==5{
					global baseline "`y'_fri"
					}					
					if dow`date'[1]==6{
					global baseline "`y'_sat"
					}

					cap qui reghdfe `y'`date' `network' if rep_stronghold==0 [aweight=pop], absorb(state_fips one##c.($baseline $full_controls1 ${other_rtgs_`network'})) cluster(`cl')
					cap eststo _`date'
					}
				coefplot $dates_coefplot_mobility_sf, $general_options_reduced $options $x_line_sf keep(`network') 
				graph export "output/dem_stronghold1996_2016_`network'_censuscontrols1_`cl'_`y'.pdf", replace
				}
		*
	}
*				
}
*
}
*

* ATUS DATA
* figure s33, figure s34
global television=1
if ${television}==1 {
preserve 
replace fxnc=abs(fxnc)
foreach var in avgmins_tv2010_2019 avgmins_tv2010_2014 avgmins_tv2015_2019 {
eststo: ivreghdfe sf_dist_fr_home22038 (`var'=fxnc) [aweight=pop], absorb(state_fips one##c.($full_controls1 ${other_rtgs_fxnc})) cluster(state_fips) first
}
restore
preserve 
replace fxnc=abs(fxnc)
di fxnc[1]
binscatterhist 	avgmins_tv2015_2019 fxnc [aweight=pop], absorb(state_fips) controls($full_controls1 ${other_rtgs_`network'}) cluster(state_fips) nquantiles(25) sample  coefficient(0.001) 
* legacy(graphregion(margin(3 6 3 6)) play(y_title_coefplot_no_legenda) graphregion(fcolor(white))  legend(off) ytitle("Effect on TV-viewership from ATUS data (RF)") xsize(8))
graph export "output/fs_atus_television2015_2019_fxnc_censuscontrols1_state_fips.pdf", replace
binscatterhist 	avgmins_tv2010_2019 fxnc [aweight=pop], absorb(state_fips) controls($full_controls1 ${other_rtgs_`network'}) cluster(state_fips) nquantiles(25) sample coefficient(0.001) 
* legacy(graphregion(margin(3 6 3 6)) play(y_title_coefplot_no_legenda) graphregion(fcolor(white))  legend(off) ytitle("Effect on TV-viewership from ATUS data (RF)") xsize(8))
graph export "output/fs_atus_television2010_2019_fxnc_censuscontrols1_state_fips.pdf", replace
restore

* 

egen med_atus2010_2019=median(avgmins_tv2010_2019)
gen  above_med_atus2010_2019=avgmins_tv2010_2019>med_atus2010_2019 if avgmins_tv2010_2019!=.
gen  below_med_atus2010_2019=avgmins_tv2010_2019<med_atus2010_2019 if avgmins_tv2010_2019!=.

* splitting by viewrship *
foreach cl in state_fips {
	foreach network in fxnc {

	* Main outcomes REDUCED
			foreach y in sd_sf_dist_fr_home sd_sf_median_nohome_time  {
				cap drop _est*
				eststo clear
					forvalues date=21946/22035 {
					if dow`date'[1]==0{
					global baseline "`y'_sun"
					}					
					if dow`date'[1]==1{
					global baseline "`y'_mon"
					}					
					if dow`date'[1]==2{
					global baseline "`y'_tue"
					}					
					if dow`date'[1]==3{
					global baseline "`y'_wed"
					}					
					if dow`date'[1]==4{
					global baseline "`y'_thu"
					}					
					if dow`date'[1]==5{
					global baseline "`y'_fri"
					}					
					if dow`date'[1]==6{
					global baseline "`y'_sat"
					}
					qui reghdfe `y'`date' `network' if above_med_atus2010_2019==1 [aweight=pop], absorb(state_fips one##c.($baseline $full_controls1  ${other_rtgs_`network'})) cluster(`cl')
					cap eststo _`date'
					}
				coefplot $dates_coefplot_mobility_sf, $general_options_reduced $x_line_sf keep(`network') 
				graph export "output/above_med_atus_2010-2019_2020_2016_`network'_censuscontrols1_`cl'_`y'.pdf", replace
				}	
				
			foreach y in sd_sf_dist_fr_home sd_sf_median_nohome_time  {
				cap drop _est*
				eststo clear
					forvalues date=21946/22035 {
					if dow`date'[1]==0{
					global baseline "`y'_sun"
					}					
					if dow`date'[1]==1{
					global baseline "`y'_mon"
					}					
					if dow`date'[1]==2{
					global baseline "`y'_tue"
					}					
					if dow`date'[1]==3{
					global baseline "`y'_wed"
					}					
					if dow`date'[1]==4{
					global baseline "`y'_thu"
					}					
					if dow`date'[1]==5{
					global baseline "`y'_fri"
					}					
					if dow`date'[1]==6{
					global baseline "`y'_sat"
					}
					reghdfe `y'`date' `network' if below_med_atus2010_2019==1 [aweight=pop], absorb(state_fips one##c.($baseline $full_controls1  ${other_rtgs_`network'})) cluster(`cl')
					cap eststo _`date'
					}
				coefplot $dates_coefplot_mobility_sf, $general_options_reduced $x_line_sf keep(`network') 
				graph export "output/below_med_atus_2010-2019_2020_2016_`network'_censuscontrols1_`cl'_`y'.pdf", replace
				}	
		*
		
	}
}
*

* interact by viewership *
gen fxnc_atus= fxnc*avgmins_tv2010_2019
foreach cl in state_fips {
	foreach network in fxnc {
			foreach y in sd_sf_dist_fr_home sd_sf_median_nohome_time  {
				cap drop _est*
				eststo clear
					forvalues date=21946/22035 {
					if dow`date'[1]==0{
					global baseline "`y'_sun"
					}					
					if dow`date'[1]==1{
					global baseline "`y'_mon"
					}					
					if dow`date'[1]==2{
					global baseline "`y'_tue"
					}					
					if dow`date'[1]==3{
					global baseline "`y'_wed"
					}					
					if dow`date'[1]==4{
					global baseline "`y'_thu"
					}					
					if dow`date'[1]==5{
					global baseline "`y'_fri"
					}					
					if dow`date'[1]==6{
					global baseline "`y'_sat"
					}
					qui reghdfe `y'`date'  `network' [aweight=pop], absorb(state_fips one##c.(`network'_atus $baseline $full_controls1  ${other_rtgs_`network'})) cluster(`cl')
					cap eststo _`date'
					}
				coefplot $dates_coefplot_mobility_sf, $general_options_reduced $x_line_sf keep(`network') 
				graph export "output/control_for_interaction_atus_2010-2019_2020_2016_`network'_censuscontrols1_`cl'_`y'.pdf", replace
				}	
		*
		
	}
}
*


}
*

* EMERGENCY DATES
* figure s35, figure s36
global safegraph_emergency=1
if ${safegraph_emergency}==1 {
foreach cl in state_fips {
	foreach network in fxnc {
			foreach y in sd_sf_dist_fr_home sd_sf_median_nohome_time  {
				cap drop _est*
				eststo clear
					forvalues date=21946/22035 {
					if dow`date'[1]==0{
					global baseline "`y'_sun"
					}					
					if dow`date'[1]==1{
					global baseline "`y'_mon"
					}					
					if dow`date'[1]==2{
					global baseline "`y'_tue"
					}					
					if dow`date'[1]==3{
					global baseline "`y'_wed"
					}					
					if dow`date'[1]==4{
					global baseline "`y'_thu"
					}					
					if dow`date'[1]==5{
					global baseline "`y'_fri"
					}					
					if dow`date'[1]==6{
					global baseline "`y'_sat"
					}

					cap qui reghdfe `y'`date' `network' [aweight=pop], absorb(state_fips one##c.(time_for_county_emerg $baseline $full_controls1 $time_death $time_case ${other_rtgs_`network'})) cluster(`cl')
					cap eststo _`date'
					}
				coefplot $dates_coefplot_mobility_sf, $general_options_reduced $options $x_line_sf keep(`network') 
				graph export "output/timeforemergency_2016_`network'_censuscontrols1_`cl'_`y'.pdf", replace
				}	
		*
		
	* Main outcomes REDUCED
			foreach y in sd_sf_dist_fr_home sd_sf_median_nohome_time  {
				cap drop _est*
				eststo clear
					forvalues date=21946/22035 {
					if dow`date'[1]==0{
					global baseline "`y'_sun"
					}					
					if dow`date'[1]==1{
					global baseline "`y'_mon"
					}					
					if dow`date'[1]==2{
					global baseline "`y'_tue"
					}					
					if dow`date'[1]==3{
					global baseline "`y'_wed"
					}					
					if dow`date'[1]==4{
					global baseline "`y'_thu"
					}					
					if dow`date'[1]==5{
					global baseline "`y'_fri"
					}					
					if dow`date'[1]==6{
					global baseline "`y'_sat"
					}

					reghdfe `y'`date' `network' [aweight=pop], absorb(state_fips one##c.(had_emergency_state $baseline $full_controls1 ${other_rtgs_`network'})) cluster(`cl')
					cap eststo _`date'
					}
				coefplot $dates_coefplot_mobility_sf, $general_options_reduced $options $x_line_sf keep(`network') 
				graph export "output/hademergency_2016_`network'_censuscontrols1_`cl'_`y'.pdf", replace
				}	
		*
	}
}

foreach variable in time_for_county_emerg had_emergency_state {
	foreach network in fxnc  {
	reghdfe `variable' `network' [aweight=pop], absorb(state_fips one##c.($full_controls1 ${other_rtgs_`network'})) cluster(state_fips) 
	binscatterhist 	`variable' `network' [aweight=pop], coef(0.00001) absorb(state_fips) cluster(state_fips) controls($full_controls1 ${other_rtgs_`network'}) nquantiles(19)  graphregion(fcolor(white))  legend(off) ytitle("Emergency Measures") xtitle("Fox News Channel Position (Standardized)")  color(teal) lcolor(maroon) 
	graph export "output/emergency_`variable'_`network'_censuscontrols1_state_fips.pdf", replace
	}
}

*				
}
*

* LEE ET AL. ADJUSTMENT
global safegraph_adj=1
if ${safegraph_adj}==1 {
* IV *
foreach cl in state_fips {
	* Main outcomes IV

			foreach y of global outcomes_pick {
					forvalues date=21946/22035 {	
					if dow`date'[1]==0{
					global baseline "`y'_sun"
					}					
					if dow`date'[1]==1{
					global baseline "`y'_mon"
					}					
					if dow`date'[1]==2{
					global baseline "`y'_tue"
					}					
					if dow`date'[1]==3{
					global baseline "`y'_wed"
					}					
					if dow`date'[1]==4{
					global baseline "`y'_thu"
					}					
					if dow`date'[1]==5{
					global baseline "`y'_fri"
					}					
					if dow`date'[1]==6{
					global baseline "`y'_sat"
					}
					cap qui ivreghdfe `y'`date' (fxnc_rtg=fxnc) [aweight=pop], absorb(state_fips one##c.($baseline $full_controls1 msnbc_rtg cnn_rtg)) cluster(`cl')
					qui lincom _b[fxnc_rtg]
					global coef_`date'=r(estimate)
					global lb_`date'=-r(se)*3.11+r(estimate)
					global ub_`date'=r(se)*3.11+r(estimate)
					macro drop baseline
					}
				matrix define matrix_coef=(${coef_21946} \ ${coef_21947} \ ${coef_21948} \ ${coef_21949} \ ${coef_21950} \ ${coef_21951} \ ${coef_21952} \ ${coef_21953} \ ${coef_21954} \ ${coef_21955} \ ${coef_21956} \ ${coef_21957} \ ${coef_21958} \ ${coef_21959} \ ${coef_21960} \ ${coef_21961} \ ${coef_21962} \ ${coef_21963} \ ${coef_21964} \ ${coef_21965} \ ${coef_21966} \ ${coef_21967} \ ${coef_21968} \ ${coef_21969} \ ${coef_21970} \ ${coef_21971} \ ${coef_21972} \ ${coef_21973} \ ${coef_21974} \ ${coef_21975} \ ${coef_21976} \ ${coef_21977} \ ${coef_21978} \ ${coef_21979} \ ${coef_21980} \ ${coef_21981} \ ${coef_21982} \ ${coef_21983} \ ${coef_21984} \ ${coef_21985} \ ${coef_21986} \ ${coef_21987} \ ${coef_21988} \ ${coef_21989} \ ${coef_21990} \ ${coef_21991} \ ${coef_21992} \ ${coef_21993} \ ${coef_21994} \ ${coef_21995} \ ${coef_21996} \ ${coef_21997} \ ${coef_21998} \ ${coef_21999} \ ${coef_22000} \ ${coef_22001} \ ${coef_22002} \ ${coef_22003} \ ${coef_22004} \ ${coef_22005} \ ${coef_22006} \ ${coef_22007} \ ${coef_22008} \ ${coef_22009} \ ${coef_22010} \ ${coef_22011} \ ${coef_22012} \ ${coef_22013} \ ${coef_22014} \ ${coef_22015} \ ${coef_22016} \ ${coef_22017} \ ${coef_22018} \ ${coef_22019} \ ${coef_22020} \ ${coef_22021} \ ${coef_22022} \ ${coef_22023} \ ${coef_22024} \ ${coef_22025} \ ${coef_22026} \ ${coef_22027} \ ${coef_22028} \ ${coef_22029} \ ${coef_22030} \ ${coef_22031} \ ${coef_22032} \ ${coef_22033} \ ${coef_22034} \ ${coef_22035})
				matrix rownames matrix_coef= _21946 _21947 _21948 _21949 _21950 _21951 _21952 _21953 _21954 _21955 _21956 _21957 _21958 _21959 _21960 _21961 _21962 _21963 _21964 _21965 _21966 _21967 _21968 _21969 _21970_21971 _21972 _21973 _21974 _21975 _21976 _21977 _21978 _21979 _21980 _21981 _21982 _21983 _21984 _21985 _21986 _21987 _21988 _21989 _21990 _21991 _21992 _21993 _21994 _21995 _21996 _21997 _21998 _21999 _22000 _22001 _22002 _22003 _22004 _22005 _22006 _22007 _22008 _22009 _22010 _22011 _22012 _22013 _22014 _22015 _22016 _22017 _22018 _22019 _22020 _22021 _22022 _22023 _22024 _22025 _22026 _22027 _22028 _22029 _22030 _22031 _22032 _22033 _22034 _22035
				matrix colnames matrix_coef=b	
				matrix matrix_coef=matrix_coef'
				
				matrix define matrix_ci=(${lb_21946} , ${lb_21947} , ${lb_21948} , ${lb_21949} , ${lb_21950} , ${lb_21951} , ${lb_21952} , ${lb_21953} , ${lb_21954} , ${lb_21955} , ${lb_21956} , ${lb_21957} , ${lb_21958} , ${lb_21959} , ${lb_21960} , ${lb_21961} , ${lb_21962} , ${lb_21963} , ${lb_21964} , ${lb_21965} , ${lb_21966} , ${lb_21967} , ${lb_21968} , ${lb_21969} , ${lb_21970} , ${lb_21971} , ${lb_21972} , ${lb_21973} ,${lb_21974} , ${lb_21975} , ${lb_21976} , ${lb_21977} , ${lb_21978} , ${lb_21979} , ${lb_21980} , ${lb_21981} , ${lb_21982} , ${lb_21983} , ${lb_21984} , ${lb_21985} , ${lb_21986} , ${lb_21987} , ${lb_21988} , ${lb_21989} , ${lb_21990} , ${lb_21991} , ${lb_21992} , ${lb_21993} , ${lb_21994} , ${lb_21995} , ${lb_21996} , ${lb_21997} , ${lb_21998} , ${lb_21999} , ${lb_22000} , ${lb_22001} , ${lb_22002} , ${lb_22003} , ${lb_22004} , ${lb_22005} , ${lb_22006} , ${lb_22007} , ${lb_22008} , ${lb_22009} , ${lb_22010} , ${lb_22011} , ${lb_22012} , ${lb_22013} , ${lb_22014} , ${lb_22015} , ${lb_22016} , ${lb_22017} , ${lb_22018} , ${lb_22019} , ${lb_22020} , ${lb_22021} , ${lb_22022} , ${lb_22023} , ${lb_22024} , ${lb_22025} , ${lb_22026} , ${lb_22027} , ${lb_22028} , ${lb_22029} , ${lb_22030} , ${lb_22031} , ${lb_22032} , ${lb_22033} , ${lb_22034} , ${lb_22035} \ ${ub_21946} , ${ub_21947} , ${ub_21948} , ${ub_21949} , ${ub_21950} , ${ub_21951} , ${ub_21952} , ${ub_21953} , ${ub_21954} , ${ub_21955} , ${ub_21956} , ${ub_21957} , ${ub_21958} , ${ub_21959} , ${ub_21960} , ${ub_21961} , ${ub_21962} , ${ub_21963} , ${ub_21964} , ${ub_21965} , ${ub_21966} , ${ub_21967} , ${ub_21968} , ${ub_21969} , ${ub_21970} , ${ub_21971} , ${ub_21972} , ${ub_21973} , ${ub_21974} , ${ub_21975} , ${ub_21976} , ${ub_21977} , ${ub_21978} , ${ub_21979} ,${ub_21980} , ${ub_21981} , ${ub_21982} , ${ub_21983} , ${ub_21984} , ${ub_21985} , ${ub_21986} , ${ub_21987} , ${ub_21988} , ${ub_21989} , ${ub_21990} , ${ub_21991} , ${ub_21992} , ${ub_21993} , ${ub_21994} , ${ub_21995} , ${ub_21996} , ${ub_21997} , ${ub_21998} , ${ub_21999} , ${ub_22000} , ${ub_22001} , ${ub_22002} , ${ub_22003} , ${ub_22004} , ${ub_22005} , ${ub_22006} , ${ub_22007} , ${ub_22008} , ${ub_22009} , ${ub_22010} , ${ub_22011} , ${ub_22012} , ${ub_22013} , ${ub_22014} , ${ub_22015} , ${ub_22016} , ${ub_22017} , ${ub_22018} , ${ub_22019} , ${ub_22020} , ${ub_22021} , ${ub_22022} , ${ub_22023} , ${ub_22024} , ${ub_22025} , ${ub_22026} , ${ub_22027} , ${ub_22028} , ${ub_22029} , ${ub_22030} , ${ub_22031} , ${ub_22032} , ${ub_22033} , ${ub_22034} , ${ub_22035})
				
			coefplot ///
			(matrix(matrix_coef),  ci(matrix_ci)  ciopts(color(olive_teal%7)) color(navy%0)) ///
			(matrix(matrix_coef),  ci(matrix_ci)  ciopts(color(teal) lwidth(vthin)) color(navy%0)) ///
			(matrix(matrix_coef),  noci color(maroon) mlwidth(thin)) ///
			, $general_options2 $x_line_multi nooffsets
			graph export "output/iv_adj_`y'.pdf", replace
			}
		*
	}
*
*				
}
*

timer off 1




